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 FAA14103; Wed, 24 Sep 2003 05:39:10 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 FAA12907 for ; Wed, 24 Sep 2003 05:39:08 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h8O3d6511501 for ; Wed, 24 Sep 2003 05:39:06 +0200 (MET DST) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2-20030924/3.7W) with ESMTP id MAA15287; Wed, 24 Sep 2003 12:38:48 +0900 (JST) To: luk_stafi@wp.pl Cc: caml-list@inria.fr Subject: Re: [Caml-list] Polymorphic class recursion (?) In-Reply-To: <000701c37e00$af476f60$c617fea9@ppp> References: <000701c37e00$af476f60$c617fea9@ppp> X-Mailer: Mew version 1.94.2 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20030924123847Z.garrigue@kurims.kyoto-u.ac.jp> Date: Wed, 24 Sep 2003 12:38:47 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 recursion:01 jacques:01 lukasz:01 luk:99 val:01 val:01 recursion:01 unification:01 workarounds:01 jacques:01 bool:01 bool:01 ocaml:01 equality:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: "Lukasz Stafiniak" > # class c1 = object val v1 : unit #c2 option = None val v2 : bool #c2 option > = None end and ['a] c2 = object val v1 : #c1 option = None end;; > Characters 59-67: > class c1 = object val v1 : unit #c2 option = None val v2 : bool #c2 option > = None end and ['a] c2 = object val v1 : #c1 option = None end;; > ^^^^^^^^ > This type unit should be an instance of type bool > > Why? This works for records. (Switching to class types (class --> class > type, without = parts) doesn't help.) The difference is that records types have an identity, while object types are equal modulo structure. What this means is that record and sum types may freely use polymorphic recursion, but object and polymorphic variant types are limited to regular recursion, as they are expanded to a regular tree during unification (to check equality). What this means in practice is there is no simple way to have polymorphically recursive types: you must necessarily introduce either a record or a sum type in the recursion. Even if you do that, the next problem is that you cannot use your own constructor polymorphically, since this would mean polymorphic recursion at the expression level. There are two workarounds for that: use a mutable polymorphic record field, or use the new recursive modules in ocaml 3.07. Anyway, that's really hard. Sorry for the inconvenience, but this kind of polymorphic methods is easier to define outside of the class. Jacques Garrigue ------------------- 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