Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques-Pascal Deplaix <jp.deplaix@gmail.com>
To: Leo White <lpw25@cam.ac.uk>
Cc: OCaml mailing list <caml-list@inria.fr>
Subject: Re: [Caml-list] Recursive fixed polymorphic variants
Date: Tue, 28 May 2013 23:01:24 +0200	[thread overview]
Message-ID: <51A51B24.4070206@gmail.com> (raw)
In-Reply-To: <86ip23frnx.fsf@cam.ac.uk>

[-- Attachment #1: Type: text/plain, Size: 1326 bytes --]

Mmmh I see. Thanks for your answer.

I spent hours to understand how ([< `A | `B of 'a ] 'a) was transformed
into ([< `B of 'a ] as 'a) and I did not saw the influence of the
polymorphism in the type-checking.

Thanks again.

On 05/28/2013 10:13 AM, Leo White wrote:
>> The thing is, if we define M.a and M.b with « unit -> [> a ] » and « 'a -> [> 'a b ] », it does compile but I don't
>> know why the previous code doesn't.
>>
>> Does somebody have any hints ?
> Your f function expects an argument of type:
>
>   ([< `A | `B of 'a ] as 'a)
>
> whilst (M.b (M.a ())) has type:
>
>   [`B of [`A]]
>
> If you try to unify these two types, you have to unify 'a with both [`A]
> and [`B of [`A]]. These types can't be unified since they are both
> closed and are not equal.
>
> If you change the definitions of M.a and M.b as you described, then (M.b
> (M.a ())) has type:
>
>   [> `B of [> `A]]
>
> If you try to unify this with the type of f's argument, you unify 'a
> with [> `A] and [> `B of [> `A]]. These types can be unified because
> they are both open and are not incompatible.
>
> Note that you can use subtyping to give the original (M.b (M.a ())) the
> type:
>
>   ([`A | `B of 'a] as 'a)
>
> which *is* unifiable with the argument type of f:
>
>   f (M.b (M.a ()) :> [`A | `B of 'a] as 'a)
>
> Regards,
>
> Leo


[-- Attachment #2: Type: text/html, Size: 1847 bytes --]

      reply	other threads:[~2013-05-28 21:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-27 16:30 Jacques-Pascal Deplaix
2013-05-28  6:36 ` Erkki Seppala
2013-05-28  8:20   ` Leo White
2013-05-28  8:13 ` Leo White
2013-05-28 21:01   ` Jacques-Pascal Deplaix [this message]

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=51A51B24.4070206@gmail.com \
    --to=jp.deplaix@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=lpw25@cam.ac.uk \
    /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