In [1]:
module type Show = sig
type t
val show : t -> unit
end
Out[1]:
In [2]:
let print (implicit S : Show) x = S.show x
Out[2]:
In [3]:
implicit module Show_int = struct
type t = int
let show x = Printf.printf "Show_int: %i\n" x
end
Out[3]:
In [4]:
implicit module Show_float_list = struct
type t = float list
let show x =
Printf.printf "Show_float: [ ";
List.iter (fun f -> Printf.printf "%f " f) x;
Printf.printf "]\n"
end
Out[4]:
In [5]:
print 4
Out[5]:
In [6]:
print [1.;2.5;-3.4]
Out[6]: