caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jeremy Yallop <yallop@gmail.com>
To: Matej Kosik <5764c029b688c1c0d24a2e97cd764f@gmail.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] a question about Ocaml semantics
Date: Fri, 26 May 2017 10:09:27 +0100	[thread overview]
Message-ID: <CAAxsn=HAkvcrA68vzmrqYN1uOOeFpnCwZu7v6zeKgEug+W7Fdw@mail.gmail.com> (raw)
In-Reply-To: <8de32ec3-f6ab-7c86-a270-7f7ccbe24d20@gmail.com>

On 26 May 2017 at 09:08, Matej Kosik
<5764c029b688c1c0d24a2e97cd764f@gmail.com> wrote:
> 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?

I'm not sure that the interaction of features here is documented
anywhere.  But your expectations seem reasonable to me.

The good news is that the behaviour changed in OCaml 4.04.0, and your
program is now accepted.  However, it's not clear (to me) that the
interaction between generalization, phantom types and variance is
quite optimal or consistent yet.  For example, I'd expect this similar
program to be accepted

   type 'a phantom = int
   let x : type a. a phantom -> int = (+) 1

but it's rejected by OCaml 4.04.1.

  parent reply	other threads:[~2017-05-26  9:09 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
2017-05-26  9:09 ` Jeremy Yallop [this message]
  -- 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='CAAxsn=HAkvcrA68vzmrqYN1uOOeFpnCwZu7v6zeKgEug+W7Fdw@mail.gmail.com' \
    --to=yallop@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;
as well as URLs for NNTP newsgroup(s).