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 XAA19457; Sun, 15 Jun 2003 23:25:32 +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 XAA19558 for ; Sun, 15 Jun 2003 23:25:31 +0200 (MET DST) Received: from mallaury.noc.nerim.net (smtp-100-sunday.noc.nerim.net [62.4.17.100]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h5FLPUH24905 for ; Sun, 15 Jun 2003 23:25:30 +0200 (MET DST) Received: from karryall.dnsalias.org (karryall.dnsalias.org [62.4.18.180]) by mallaury.noc.nerim.net (Postfix) with ESMTP id 4F82C62E16; Sun, 15 Jun 2003 23:25:27 +0200 (CEST) Received: by karryall.dnsalias.org (Postfix, from userid 500) id 324491A001E; Sun, 15 Jun 2003 23:25:29 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16108.58441.74309.805809@karryall.dnsalias.org> Date: Sun, 15 Jun 2003 23:25:29 +0200 From: Olivier Andrieu To: Berke Durak Cc: caml-list@inria.fr Subject: Re: [Caml-list] Unbound type variables -- where is the .. ? In-Reply-To: <20030615204917.GA12921@liafa.jussieu.fr> References: <20030615204917.GA12921@liafa.jussieu.fr> X-Mailer: VM 7.16 under Emacs 21.2.1 From: Olivier Andrieu X-Spam: no; 0.00; andrieu:01 caml-list:01 berke:01 durak:01 toto:01 variants:01 int:01 polymorphic:01 olivier:02 variant:02 titi:02 implicit:02 unbound:02 classes:03 variable:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Berke Durak [Sunday 15 June 2003] : > > Hello > > I get the following... > > # class toto = object method zizi = function | `Alpha -> 1 | `Beta -> 2 end;; > Some type variables are unbound in this type: > class toto : object method zizi : [< `Alpha | `Beta] -> int end > The method zizi has type [< `Alpha | `Beta] -> int where .. is unbound > > Where is the .. ? Is there no way to use polymorphic variants inside > classes ? There are 3 solutions : 1) add a type constraint that "closes" the variant : ,---- | # class toto = object method zizi : [ `Alpha | `Beta] -> int = | function | `Alpha -> 1 | `Beta -> 2 end;; | class toto : object method zizi : [ `Alpha | `Beta] -> int end `---- 2) add a class parameter : ,---- | # class ['a] toto = object method zizi : 'a = function | `Alpha -> 1 | | `Beta -> 2 end;; | class ['a] toto : | object | constraint 'a = [< `Alpha | `Beta] | method zizi : 'a -> int | end `---- 3) use a polymorphic method : ,---- | # class toto = object method zizi : 'a. ([< `Alpha | `Beta] as 'a) -> int = | function | `Alpha -> 1 | `Beta -> 2 end ;; | class toto : object method zizi : [< `Alpha | `Beta] -> int end `---- About the "..", it appears in object types : ,---- | # class titi = object method a o = o#b end ;; | | Characters 5-40: | class titi = object method a o = o#b end ;; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | Some type variables are unbound in this type: | class titi : object method a : < b : 'a; .. > -> 'a end | The method a has type < b : 'a; .. > -> 'a where .. is unbound `---- It's the same problem with polymorphic variants, there's an implicit type variable that must be bound in the class definition. -- Olivier ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners