Add tags

Add tags to the following comment
functorで。各演算子は正規化したものを表示して、結果を返すようにしています。

- structure M10 = Modular (val m = 10);
- open M10;
- map (fn x => x) [1 + 2, 7 + 3, 11 + 12];
1 + 2 = 3
7 + 3 = 0
11 + 12 = 1 + 2 = 3
val it = [3,0,3] : int list
- map (fn x => x) [3 - 2, 2 - 3];
3 - 2 = 1
2 - 3 = 9
val it = [1,9] : int list
- map (fn x => x) [2 * 3, 11 * 12, 18 * 39];
2 * 3 = 6
11 * 12 = 1 * 2 = 2
18 * 39 = 8 * 9 = 2
val it = [6,2,2] : int list
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
functor Modular (val m : int) = struct
  infix 7 *
  infix 6 + -

  local
    fun calc f x y s =
      let
        open Int

        val _ = print (toString x ^ " " ^ s ^ " " ^ toString y ^ " = ")
        val x' = x mod m and y' = y mod m
        val _ = if x >= m orelse y >= m then
                  print (toString x' ^ " " ^ s ^ " " ^ toString y' ^ " = ")
                else ()
        val result = f (x', y') mod m
      in
        print (toString result ^ "\n");
        result
      end
  in
    fun x + y = calc Int.+ x y "+"
    fun x - y = calc Int.- x y "-"
    fun x * y = calc Int.* x y "*"
  end

end

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...