module type Show = sig type t val show : t -> string end module ShowInt : Show with type t = int = struct type t = int let show = Int.to_string end module ShowFloat : Show with type t = float = struct type t = float let show = Float.to_string end (* with a functor *) module F(M : Show) = struct let f = M.show end let x = let module F_int = F(ShowInt) in let module F_float = F(ShowFloat) in F_int.f 42, F_float.f 3.14 (* with a first-class module *) let f (type a) (module M : Show with type t = a) x = M.show x let x = f (module ShowInt) 42, f (module ShowFloat) 3.14