caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Christophe.Raffalli@univ-savoie.fr
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] polymorphic variant
Date: Fri, 21 Sep 2007 15:54:02 +0900 (JST)	[thread overview]
Message-ID: <20070921.155402.213471450.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <46F35FB3.6060304@univ-savoie.fr>

From: Christophe Raffalli <Christophe.Raffalli@univ-savoie.fr>
> > The above behaviour was correctly explained by Martin Jambon, but I'll
> > add some detail:
> > The type of f is actually an instance of the type of g, where the
> > first and second columns of the pattern were unified. The reason for
> > that is that in f the 1st line returns the 2nd column, and the 2nd
> > line the first column. Since the return type has to be unique, this
> > unifies x and y, i.e. the 1st and 2nd columns.
> >
> > I hope this clarifies the situation.
> >
> > Jacques Garrigue
> >   
> OK, I understand. But I would prefer if the decision to close or not the
> pattern (and therefore
> make the last case useless) did not depend upon the right members ...

So actually you didn't understand :-)
The point here is that the typing for the pattern matching is
determined completely independently of the right members. This is only
afterwards that some extra unifications may happen, as is always the
case with type inference. This is not a "decision", but a natural
consequence of the type system.
The warning about the useless case is actually a clever trick: rather
than immediately checking for useless cases after checking the pattern
matching, it waits for the whole expression to be typed, in order to
be more accurate.

In some way what you are saying is a bit like:

# let f (x : [> `A]) (y : [> `B]) = ignore [x;y] ;;
val f : ([> `A | `B ] as 'a) -> 'a -> unit = <fun>

Why are the types for x and y unified, I'd much prefere them to be
independent...

By the way, as Martin Jambon explained, you can protect you variables
against type propagation with the "as" syntax.

# let f (`A as x) (`B as y) = [x;y];;
val f : [< `A ] -> [< `B ] -> [> `A | `B ] list = <fun>


Jacques Garrigue


      reply	other threads:[~2007-09-21  6:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-20 15:05 Christophe Raffalli
2007-09-20 16:59 ` [Caml-list] " Martin Jambon
2007-09-21  0:13 ` Jacques Garrigue
2007-09-21  6:07   ` Christophe Raffalli
2007-09-21  6:54     ` Jacques Garrigue [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=20070921.155402.213471450.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=Christophe.Raffalli@univ-savoie.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;
as well as URLs for NNTP newsgroup(s).