From: Leo White <lpw25@cam.ac.uk>
To: Jacques-Pascal Deplaix <jp.deplaix@gmail.com>
Cc: OCaml mailing list <caml-list@inria.fr>
Subject: Re: [Caml-list] Recursive fixed polymorphic variants
Date: Tue, 28 May 2013 09:13:38 +0100 [thread overview]
Message-ID: <86ip23frnx.fsf@cam.ac.uk> (raw)
In-Reply-To: <51A38A23.9000402@gmail.com> (Jacques-Pascal Deplaix's message of "Mon, 27 May 2013 18:30:27 +0200")
>
> 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
next prev parent reply other threads:[~2013-05-28 8:12 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 [this message]
2013-05-28 21:01 ` Jacques-Pascal Deplaix
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=86ip23frnx.fsf@cam.ac.uk \
--to=lpw25@cam.ac.uk \
--cc=caml-list@inria.fr \
--cc=jp.deplaix@gmail.com \
/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