From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA12099; Wed, 19 Sep 2001 14:55:52 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA12111 for ; Wed, 19 Sep 2001 14:54:30 +0200 (MET DST) Received: from tet.kurims.kyoto-u.ac.jp (L013049.ppp.dion.ne.jp [211.126.13.49]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f8JCsQX02558 for ; Wed, 19 Sep 2001 14:54:27 +0200 (MET DST) Received: from localhost (localhost [127.0.0.1]) by tet.kurims.kyoto-u.ac.jp (8.11.3/8.11.3) with ESMTP id f8JCjOG02035; Wed, 19 Sep 2001 21:45:24 +0900 (JST) (envelope-from garrigue@kurims.kyoto-u.ac.jp) To: patrick@watson.org Cc: caml-list@inria.fr Subject: Re: [Caml-list] Polymorphic variant abbreviations In-Reply-To: References: X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20010919214524Z.garrigue@kurims.kyoto-u.ac.jp> Date: Wed, 19 Sep 2001 21:45:24 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I have some code that would like to use polymorphic type abbreviations > along with labels. It seems to be not behaving quite like I expected. > What could I do to make this shorter: > > type a = [ `A ] > > let f ~a:(#a as a) = ... Nothing. But this doesn't strike me as a very frequent idiom. > I was hoping that I could use this: > > let f ~a:#a = ... > > but then it says that 'a' is unbound. Sure, nothing binds a here: ~a: is a label, and #a an abbreviation for `A. > I also find that the error messages are not as useful as they could be > with the type abbreviations. E.g: > > This expression has type ... but is here used with #a as 'a = 'a Could you give me the code leading to this error message? This is clearly a bug. > The last 2 questions were about possible minor improvements with using > abbreviations. Now I'm stumped - can anyone bail me out? > > (* Some type definitions and abbreviations *) > type t = ([ `A of 'a list | `B | `C ]) as 'a > type b = [ `B ] > type c = [ `C ] > > (* A rename for one of the abbreviations *) > type b2 = b > > (* > this doesn't compile - says unbound class b2 > > let g2 ~(xs : #b2 list) = > `A xs > *) I see. This is rather unexpected. I'll try to correct this, but the problem is a bit involved. > (* The first works as I would expect, the second gives a very unexpected > type. There seems to be some kind of unexpected unification going on > between terms. *) > > let h1 (#b as x1) (#c as x2) = `A [x1; x2] > let h2 (x1 : #b) (x2 : #c) = `A [x1; x2] (#b as x1) and (x1 : #b) have completely different meanings. The first one is just equivalent to (`B as x1), and gives x1 the type [> `B]. The second one constrains x1 to have type #b = [< `B]. So in h2 you unify [< `A] and [< `B], which leaves no possible constructor... I think that I will make it an error, because this is confusing. Jacques Garrigue ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr