Advertisement
Guest User

explicit dicts

a guest
Sep 7th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1.  
  2. module type TC =
  3. sig
  4. type t
  5. val x : t -> t -> t
  6. val y : t -> unit
  7. end
  8.  
  9. module X1 =
  10. struct
  11. type t = int
  12. let x = (+)
  13. let y = Printf.printf "%d\n"
  14. end
  15.  
  16. (* this is 3.12.1, you can drop most most type annotations in 4.00 *)
  17. let f (type a) (tc : (module TC with type t = a)) (x : a) : a=
  18. let module M = (val tc : TC with type t = a) in
  19. M.x x x
  20.  
  21. #use "tc.ml";;
  22. module type TC = sig type t val x : t -> t -> t val y : t -> unit end
  23. module X1 :
  24. sig type t = int val x : int -> int -> int val y : int -> unit end
  25. val f : (module TC with type t = 'a) -> 'a -> 'a = <fun>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement