From: Jacques Carette <carette@mcmaster.ca>
To: caml-list@inria.fr
Subject: Why is this coercion necessary?
Date: Wed, 13 Aug 2008 22:18:34 -0400 [thread overview]
Message-ID: <48A395FA.2050704@mcmaster.ca> (raw)
Here is a much simplified version from a (much) larger problem I have
recently encountered:
type 'a a = [`A of 'a b]
and 'a b = [`B of 'a a]
and 'a c = [`C ]
type 'a d = [ 'a a | 'a b | 'a c]
type e = e d
# this code gives an error (details below)
let f1 (x:e) : e = match x with
| `A n -> n
| `B n -> n
| `C -> `C
# this works
let f2 (x:e) : e = match x with
| `A n -> (n :> e)
| `B n -> (n :> e)
| `C -> `C
f1 gives an error on the "| `B n -> n" line, pointing to the second 'n'
with
This expression has type e a but is used with type e b
These two variant types have no intersection
Indeed, they have no intersection, but they have a union! That is what
it seems the coercion in f2 'forces' the type-checker to realize, and
all works fine. But of course, such coercions end up polluting my code
all over the place (since the actual example is made of 9 types with 20
tags in total, and the 'recursive knot' requires 2 parameters to close
properly).
So, is this a bug? Is there a way to avoid these coercions?
Jacques
next reply other threads:[~2008-08-14 2:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-14 2:18 Jacques Carette [this message]
2008-08-14 11:21 ` [Caml-list] " Lukasz Stafiniak
2008-08-14 11:31 ` Lukasz Stafiniak
2008-08-14 15:22 ` Martin Jambon
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=48A395FA.2050704@mcmaster.ca \
--to=carette@mcmaster.ca \
--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