From: Philippe Veber <philippe.veber@gmail.com>
To: Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com>
Cc: caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] a question about Ocaml semantics
Date: Fri, 26 May 2017 10:38:29 +0200 [thread overview]
Message-ID: <CAOOOohTj2Oac7H3xCJnsTR4QSDJ33tOv3eStG0h3c-LEwMewZw@mail.gmail.com> (raw)
In-Reply-To: <8de32ec3-f6ab-7c86-a270-7f7ccbe24d20@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1413 bytes --]
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
>
[-- Attachment #2: Type: text/html, Size: 2517 bytes --]
next prev parent reply other threads:[~2017-05-26 8:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-26 8:08 Matej Kosik
2017-05-26 8:38 ` Philippe Veber [this message]
2017-05-26 9:09 ` Jeremy Yallop
-- strict thread matches above, loose matches on Subject: below --
2017-04-26 14:26 Matej Kosik
2017-04-26 20:09 ` Jeremy Yallop
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAOOOohTj2Oac7H3xCJnsTR4QSDJ33tOv3eStG0h3c-LEwMewZw@mail.gmail.com \
--to=philippe.veber@gmail.com \
--cc=5764c029b688c1c0d24a2e97cd764f@gmail.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox