Advertisement
Guest User

Untitled

a guest
Sep 12th, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. module type SHOW =
  2. sig
  3. type t
  4. val show : t -> string
  5. end
  6.  
  7. let print (implicit Show : SHOW) x = Show.show x
  8.  
  9. implicit module ShowInt = struct type t = int let show = string_of_int end
  10. implicit module ShowFloat = struct type t = float let show = string_of_float end
  11.  
  12. implicit functor ShowPair (Show1 : SHOW) (Show2 : SHOW) =
  13. struct
  14. type t = Show1.t * Show2.t
  15. let show (x, y) = "(" ^ Show1.show x ^ ", " ^ Show2.show y ^ ")"
  16. end
  17.  
  18. (* none of these work *)
  19.  
  20. let rec grow_pairs (implicit Show : SHOW) x =
  21. grow_pairs (x, x)
  22.  
  23. let rec grow_pairs (implicit Show : SHOW) x =
  24. let module Show2 = ShowPair (Show) (Show) in
  25. grow_pairs (implicit Show2) (x, x)
  26.  
  27. let rec grow_pairs (type a) (implicit Show : SHOW with type t = a) (x : a) =
  28. let module Show2 = ShowPair (Show) (Show) in
  29. grow_pairs (implicit Show2) (x, x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement