Hi Matej,

I'm no expert, but I'm pretty sure the problem here is related to the value restriction [0]. If you change the last line to:

# let _ = f { enter = fun x -> (+) 1 x } ;;
- : int = 3

there is no typing error anymore. Note that with ocaml 4.04.0 and 4.04.1, your original definition is accepted.

hope this helps,
  Philippe.

[0] https://caml.inria.fr/pub/papers/garrigue-value_restriction-fiwflp04.pdf



2017-05-26 10:08 GMT+02:00 Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com>:
Hi,

There's an Ocaml language feature I do not understand.

E.g. in this example:

  type 'a phantom = int
  type t = { enter : 'a. 'a phantom -> int }
  let f g = g.enter 2
  let _ = f { enter = fun x -> 1 + x } (* ok *)
  let _ = f { enter = (+) 1 }          (* fails to typecheck *)

I don't get why, if we have:

  type 'a phantom = int

i.e. "'a phantom" is defined as an alias of "int",
how is it possible that the following types:

  { enter : 'a. 'a phantom -> int }

is not equal to

  { enter : 'a. int -> int }

I've tried to find a corresponding section in the Reference Manual, but I failed.
Where is this explained?

--
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs