From: Nils Gesbert <nils.gesbert@ens.fr>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Oddness with recursive polymorphic variants
Date: Thu, 4 May 2006 21:03:19 +0200 [thread overview]
Message-ID: <20060504210319.5e05f7a6.nils.gesbert@ens.fr> (raw)
In-Reply-To: <445A22BA.4070807@sms.ed.ac.uk>
Jeremy Yallop <j.d.yallop@sms.ed.ac.uk> a écrit :
» I have two polymorphic variant types, as follows:
»
» type f = [`A | `B of f]
» type g = [f | `C]
»
» Next, I have a function from f to g:
»
» let s1 : f -> g = function
» | `A -> `A
» | `B b -> b
»
» Sadly, the compiler rejects this:
»
» Characters 57-58:
» | `B b -> b;;
» ^
» This expression has type f but is here used with type g
» The first variant type does not allow tag(s) `C
»
» The error message seems odd. Why should it matter that g has more tags
» than f, since every value of f is a value of g (by definition)?
f is indeed a subtype of g, but to forget the precise type of b (that is, forget the information that it cannot contain the tag `C), you have to use explicit coercion, i. e. :
let s1 : f -> g = function
| `A -> `A
| `B b -> (b :> g)
next prev parent reply other threads:[~2006-05-04 19:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-04 15:50 Jeremy Yallop
2006-05-04 19:03 ` Nils Gesbert [this message]
2006-05-04 20:30 ` [Caml-list] " Nils Gesbert
2006-05-05 8:04 ` Jeremy Yallop
2006-05-04 15:54 Jeremy Yallop
2006-05-04 17:10 ` [Caml-list] " Luc Maranget
2006-05-04 18:26 ` Michael Wohlwend
2006-05-04 18:33 ` brogoff
2006-05-04 18:58 ` Jeremy Yallop
2006-05-05 0:01 ` brogoff
2006-05-05 6:43 ` Luc Maranget
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=20060504210319.5e05f7a6.nils.gesbert@ens.fr \
--to=nils.gesbert@ens.fr \
--cc=caml-list@yquem.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