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
omoikani
#4939()
[
StandardML
]
Rating1/1=1.00
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 endRating1/1=1.00-0+
[ reply ]