caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christian Stork <cstork@ics.uci.edu>
To: Jean-Marie Gaillourdet <jmg@gaillourdet.net>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Using Polymorphic Variants
Date: Sun, 2 Oct 2005 09:45:08 -0700	[thread overview]
Message-ID: <20051002164508.GA1686@anthony.ics.uci.edu> (raw)
In-Reply-To: <433F9DBE.6020509@gaillourdet.net>

On Sun, Oct 02, 2005 at 10:43:42AM +0200, Jean-Marie Gaillourdet wrote:
> Christian Stork schrieb:
> > Basic Question:  

> >     Why aren't polymorphic variants coerced by default?

> I guess there is some undecidability involved.

My guess too, but I'd like to be sure. ;-)

> > I am automatically generating some code that uses polymorphic variants
> > extensively.  The inferred types are very complicated.  Unfortunatly, at
> > some points in my code coercions are needed for it to compile.  Since I
> > don't have the types available when I generate the code (and I don't
> > think it's possible to refer to inferred types in coercions) I can't
> > coerce explicitly.  I'd like to be able to say something like:

> >     ... f (x: type_of_x :> type_expected_by_f) ...
> Isn't it possible to write something like that:

>  (f: 'a) (x: type_of_x :> 'a)

> I didn't test that trick.

Nice idea.  Let's see:


# type ab  = [ `Apple | `Banana ]
  type abo = [ ab | `Orange]
  let f (x:abo) = match x with #ab -> "ab" | #abo -> "orange"
  let a = (`Apple:ab);;
type ab = [ `Apple | `Banana ]
type abo = [ `Apple | `Banana | `Orange ]
val f : abo -> string = <fun>
val a : ab = `Apple
# f (a:>abo);;
- : string = "ab"
# (f:'a->_) (a:ab:>'a);;
Characters 10-20:
  (f:'a->_) (a:ab:>'a);;
            ^^^^^^^^^^
Type ab = [ `Apple | `Banana ] is not a subtype of type
  abo = [ `Apple | `Banana | `Orange ] 
The first variant type does not allow tag(s) `Orange
# (f:'a->_) (a:>'a);;
Characters 11-12:
  (f:'a->_) (a:>'a);;
             ^
This expression cannot be coerced to type
  abo = [ `Apple | `Banana | `Orange ];
it has type ab but is here used with type abo
The first variant type does not allow tag(s) `Orange


I'm confused about the error message saying that ab is not a subtype of
abo.  I thought it is...

-- 
Chris Stork   <>  Support eff.org!  <>   http://www.ics.uci.edu/~cstork/
OpenPGP fingerprint:  B08B 602C C806 C492 D069  021E 41F3 8C8D 50F9 CA2F


  parent reply	other threads:[~2005-10-02 16:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-02  0:06 UsingPolymorphic Variants Christian Stork
     [not found] ` <433F9DBE.6020509@gaillourdet.net>
2005-10-02 16:45   ` Christian Stork [this message]
2005-10-03 13:55     ` [Caml-list] Using Polymorphic Variants Jacques Garrigue

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=20051002164508.GA1686@anthony.ics.uci.edu \
    --to=cstork@ics.uci.edu \
    --cc=caml-list@inria.fr \
    --cc=jmg@gaillourdet.net \
    /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).