From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: maf@microsoft.com
Cc: caml-list@inria.fr
Subject: Re: # types and polymorphic variants
Date: Sat, 26 Feb 2000 23:10:06 +0900 [thread overview]
Message-ID: <20000226231006O.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: Your message of "Thu, 24 Feb 2000 12:51:11 -0800" <783D93998201D311B0CF00805FEAA07B7E9115@RED-MSG-42>
From: Manuel Fahndrich <maf@microsoft.com>
> What is the meaning of #foo, when foo is a polymorphic variant set?
>
> type foo = [`A | `B | `C]
>
> I assumed that it was the following:
>
> #foo = [<`A | `B | `C ]
>
> that is a set containing at most `A | `B | `C. In other words a subtype of
> foo.
This is correct. Notice however that [> `A | `B | `C] would also be a
subtype of foo (although from a different point of view), so there is
a choice done here between two possibilities, and I took the seemingly
most useful/intuitive.
> But consider the following example.
[...]
It seems that you found a bug in ocaml-2.99. If you are particularly
interested in variants, I suggest you switch to the CVS version.
With the current CVS version it works as you expect:
Objective Caml version 2.99+6 (2000/02/25)
# type foo = [`A|`B|`C];;
type foo = [`A|`B|`C]
# let foo1 (x : #foo) = x;;
val foo1 : (#foo as 'a) -> 'a = <fun>
# let y1 = foo1 (`A : [`A]);;
val y1 : [`A] = `A
# let foo2 (#foo as x) = x;;
val foo2 : #foo -> [>`A|`B|`C] = <fun>
# foo2 (`A : [`A]);;
- : _[>`A|`B|`C] = `A
foo2 shows the difference between the type #foo, and the pattern #foo,
which intuitively accepts all values of type #foo, but also permits
type refinement when combined with "as".
> The first function returns me only a foo, the second function returns me
> [`A] as expected. Thus my question, what exactly does #foo stand for. I do
> understand row variables, but the issue with the lower and upper bounds > <
> in variant types seems new. Is there a paper describing these?
The answer is that your intuition was correct.
You will find a description of variants in "Programming with polymorphic
variants", ML Workshop '98, Baltimore. You can get it from my home
page.
In fact the system in ocaml 3 is a refinement of that, forgetting the
type of a tag when it disappears from the upper bound, but this
shouldn't matter in most cases.
Jacques
---------------------------------------------------------------------------
Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp
<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>
prev parent reply other threads:[~2000-02-28 23:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-02-24 20:51 Manuel Fahndrich
2000-02-26 14:10 ` 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=20000226231006O.garrigue@kurims.kyoto-u.ac.jp \
--to=garrigue@kurims.kyoto-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=maf@microsoft.com \
/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