Advertisement
Guest User

Untitled

a guest
Mar 20th, 2014
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module type Functor = sig
  2.     type 'a t
  3.     val fmap : ('a -> 'b) -> 'a t -> 'b t
  4.   end
  5.  
  6. (* first version: DOES NOT WORK *)
  7. let makeFunctor1 (type s) ~fmap =
  8.   let module S = struct
  9.     type 'a t = s
  10.     let fmap = fmap
  11.   end
  12.   in (module S : Functor with type t = s)
  13.  
  14. module MyF = (val makeFunctor ~fmap:(fun f v -> match (f, v) with
  15.                                       | (f, (Some x)) -> Some (f x)
  16.                                       | (_, None) -> None))
  17.  
  18. =>
  19. Error: In this `with' constraint, the new definition of t
  20.        does not match its original definition in the constrained signature:
  21.        Type declarations do not match: type t is not included in type 'a t
  22.        They have different arities.
  23.  
  24. (* second version: DOES NOT WORK EITHER *)
  25. let makeFunctor (type s) ~fmap =
  26.   let module S = struct
  27.     type 'a t = s
  28.     let fmap = fmap
  29.   end
  30.   in (module S : Functor with type 'a t = s)
  31.  
  32. =>
  33. Parse error: [ident] expected after "type" (in [package_type_cstr])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement