From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA30843 for caml-redistribution@pauillac.inria.fr; Tue, 29 Feb 2000 00:09:11 +0100 (MET) Resent-Message-Id: <200002282309.AAA30843@pauillac.inria.fr> Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA04864 for ; Mon, 28 Feb 2000 02:41:29 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id CAA10844 for ; Mon, 28 Feb 2000 02:41:26 +0100 (MET) Received: from tet.kurims.kyoto-u.ac.jp (tet.kurims.kyoto-u.ac.jp [130.54.16.184]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id KAA01600; Mon, 28 Feb 2000 10:41:24 +0900 (JST) Received: from localhost (localhost [127.0.0.1]) by tet.kurims.kyoto-u.ac.jp (8.9.3/8.9.3) with ESMTP id XAA16423; Sat, 26 Feb 2000 23:10:06 +0900 (JST) (envelope-from garrigue@kurims.kyoto-u.ac.jp) To: maf@microsoft.com Cc: caml-list@inria.fr Subject: Re: # types and polymorphic variants In-Reply-To: Your message of "Thu, 24 Feb 2000 12:51:11 -0800" <783D93998201D311B0CF00805FEAA07B7E9115@RED-MSG-42> References: <783D93998201D311B0CF00805FEAA07B7E9115@RED-MSG-42> X-Mailer: Mew version 1.93 on Emacs 20.4 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20000226231006O.garrigue@kurims.kyoto-u.ac.jp> Date: Sat, 26 Feb 2000 23:10:06 +0900 From: Jacques Garrigue X-Dispatcher: imput version 980905(IM100) Resent-From: weis@pauillac.inria.fr Resent-Date: Tue, 29 Feb 2000 00:09:11 +0100 Resent-To: caml-redistribution@pauillac.inria.fr From: Manuel Fahndrich > 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 = # let y1 = foo1 (`A : [`A]);; val y1 : [`A] = `A # let foo2 (#foo as x) = x;; val foo2 : #foo -> [>`A|`B|`C] = # 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 JG