Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module type SHOW =
- sig
- type t
- val show : t -> string
- end
- let print (implicit Show : SHOW) x = Show.show x
- implicit module ShowInt = struct type t = int let show = string_of_int end
- implicit module ShowFloat = struct type t = float let show = string_of_float end
- implicit functor ShowPair (Show1 : SHOW) (Show2 : SHOW) =
- struct
- type t = Show1.t * Show2.t
- let show (x, y) = "(" ^ Show1.show x ^ ", " ^ Show2.show y ^ ")"
- end
- (* none of these work *)
- (* this works *)
- let rec grow_pairs : 'a. (implicit Show : SHOW with type t = 'a) -> Show.t -> 'b =
- fun (type a) (implicit Show : SHOW with type t = a) x ->
- let module Show2 = ShowPair (Show) (Show) in
- grow_pairs (implicit Show2) (x, x)
- (* but this doesn't, and the error message is strange *)
- let rec grow_pairs2 : 'a. (implicit Show : SHOW with type t = 'a) -> 'a -> 'b =
- fun (type a) (implicit Show : SHOW with type t = a) x ->
- let module Show2 = ShowPair (Show) (Show) in
- grow_pairs2 (implicit Show2) (x, x)
- (*
- Error: This expression has type
- (implicit Show : SHOW with type t = 'a) -> Show.t -> 'b
- but an expression was expected of type
- (implicit Show : SHOW with type t = 'a) -> 'a -> 'b
- The type variable 'a occurs inside 'a
- *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement