module Num : sig
type 'a t
val (+) : $:'a t -> 'a -> 'a -> 'a
val (-) : $:'a t -> 'a -> 'a -> 'a
val int : int t
val float : float t
end = struct
class type ['a] _t = object
method plus : 'a -> 'a -> 'a
method minus : 'a -> 'a -> 'a
end
type 'a t = 'a _t
let (+) $:d = d#plus
let (-) $:d = d#minus
open Pervasives
let int = object method plus = (+) method minus = (-) end
let float = object method plus = (+.) method minus = (-.) end
end
open Num
let double x = x + x
let _ =
assert (1 + 2 = 3);
assert (1.2 + 3.4 = 4.6);
assert (2 - 1 = 1);
assert (1.2 - 1.2 = 0.0);
assert (double 1 = 2 );
assert (double 1.2 = 2.4)