Advertisement
Guest User

Untitled

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