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 VAA29115 for caml-red; Wed, 11 Oct 2000 21:55:17 +0200 (MET DST) 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 UAA28184 for ; Wed, 11 Oct 2000 20:54:20 +0200 (MET DST) Received: from shell5.ba.best.com (shell5.ba.best.com [206.184.139.136]) by concorde.inria.fr (8.10.0/8.10.0) with ESMTP id e9BIsJb11555 for ; Wed, 11 Oct 2000 20:54:19 +0200 (MET DST) Received: from localhost (bpr@localhost) by shell5.ba.best.com (8.9.3/8.9.2/best.sh) with ESMTP id LAA21174; Wed, 11 Oct 2000 11:54:10 -0700 (PDT) Date: Wed, 11 Oct 2000 11:54:10 -0700 (PDT) From: Brian Rogoff To: malc cc: caml-list@inria.fr Subject: Re: Polymorphic variants in class methods In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis@pauillac.inria.fr On Mon, 9 Oct 2000, malc wrote: > # class foo = object method moo = `Bar end;; > Some type variables are unbound in this type: > class foo : object method moo : [> `Bar] end > The method moo has type [> `Bar] where 'a is unbound > > Someone care to comment on that? As Jacques Garrigue has pointed out, typing of polymorphic variants is subtle, and the interaction of polymorphic variant and object typing is very subtle. Let me try and explain simply and an expert can tell if I am wrong or inaccurate... Types described by "[>" are polymorphic and can be extended with new tags, so they have an implicit type variable. OCaml classes can be polymorphic, but methods must be monomorphic, so your example is similar to # class foo = object method moo = List.length end;; Some type variables are unbound in this type: class foo : object method moo : 'a list -> int end The method moo has type 'a list -> int where 'a is unbound Now, an oft discussed extension to OCaml is polymorphic methods (and an even more oft discussed extension would allow polymorphic recursion in the core (non OO) language) which would have you explicitly provide the type for that method. This was supported in OLabl. I don't know the OLabl incantation to type your program, but for the example I gave I think it is class foo = object method moo : 'a . 'a list -> int = List.length end;; One way to make your program typecheck is to define the set of variants you want to deal with, like so. # type t = [`Foo | `Bar | `Baz];; type t = [ `Foo | `Bar | `Baz] # class foo = object method moo : t = `Bar end;; class foo : object method moo : t end > P.S. Uhm, like im totaly lost on whats going on here. Ummm, like I totally hope this helps, dude. :-) I think you'll want to at least read "Programming with Polymorphic Variants" which you can download from http://wwwfun.kurims.kyoto-u.ac.jp/soft/olabl/ -- Brian