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 09:13:37 +0900 (JST) [thread overview]
Message-ID: <20070921.091337.134531783.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <46F28C38.2080801@univ-savoie.fr>
From: Christophe Raffalli <Christophe.Raffalli@univ-savoie.fr>
> Can someone explain to me why the two following functions are typed so
> differently:
>
> ---------------
> Objective Caml version 3.10.0
>
> # let f = function
> `T, y -> y
> | x, `T -> x
> | `F, `F -> `F
> | `F, _ -> `F
> ;;
> Warning U: this match case is unused.
> val f : [ `F | `T ] * [ `F | `T ] -> [ `F | `T ] = <fun>
>
> # let g = function
> `T, y -> y
> | x, `T -> `F
> | `F, `F -> `F
> | `F, _ -> `F
> ;;
> val g : [< `F | `T ] * ([> `F | `T ] as 'a) -> 'a = <fun>
>
> -------
>
> The decision to close the second column seems to depend upon the
> right hand side of the pattern, which seems excluded by Jacques
> Garrigue's paper about deep pattern matching ... According to this
> paper, the second function is strangely typed. What is implemented
> in OCaml ?
It is implemented, and correctly I believe.
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
next prev parent reply other threads:[~2007-09-21 0:12 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 [this message]
2007-09-21 6:07 ` Christophe Raffalli
2007-09-21 6:54 ` 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=20070921.091337.134531783.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