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 DAA10538; Mon, 23 Jun 2003 03:14:32 +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 DAA10420 for ; Mon, 23 Jun 2003 03:14:31 +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 h5N1ETT09256 for ; Mon, 23 Jun 2003 03:14:29 +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/3.7W) with ESMTP id KAA28455; Mon, 23 Jun 2003 10:14:15 +0900 (JST) To: asl@tercom.ru Cc: caml-list@inria.fr Subject: Re: [Caml-list] Mutual recursion between classes and types in OCaml In-Reply-To: <20030621145534.GA3820@polymorph.dorms.spbu.ru> References: <20030621145534.GA3820@polymorph.dorms.spbu.ru> 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: <20030623101423H.garrigue@kurims.kyoto-u.ac.jp> Date: Mon, 23 Jun 2003 10:14:23 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Spam: no; 0.00; jacques:01 caml-list:01 recursion:01 tercom:01 val:01 faq:01 datatype:01 semantical:01 mli:01 silently:01 unsound:01 inference:01 wwwfun:01 explicitely:01 ocaml:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Anton Lavrik > I suppose it's quite useful to define object types and "ordinary" types, so > that they could refer to each other. For example, > > class c = > object val v = A 0 (* constructor `A' is not bound *) > end > > [...] (* some syntactic construct like `and' keyword *) > > type t = A of int | B of c (* now type `t' and constructor `A' are > defined *) The solution is a FAQ, you just have to parameterize your datatype with the type of the class (opening the recursion), and everything will be fine. > So why mutual recursion between classes and types is not allowed? Is this > fundamental or technical problem? I can't find any references denoting that > problem. This is technical, but has theoretical implications too. Technical problem: typing of classes definitions and type definitions are completely independent, and both of them are rather complex. Mixing the two is practically hard. Semantical problem: the handling of constraints in type definitions and class definitions is different. Types allow polymorphic recursion, and you must give all the constraints explicitely for every type (what you write in the .mli is the real type). With classes, constraints are propagated silently (so they may be only implicit in the .mli), and there is no polymorphic recursion. Mixing the two might be confusing, or unsound. > BTW, what does `-rectypes' ocamlc's option really mean (there are quite a > few words about it in reference manual)? And how does it concern the > subject? This is unrelated. It allows you two build arbitrary recursive types through type inference # let rec depth (_,l) = 1 + List.fold_left max 0 (List.map depth l);; val depth : ('b * 'a list as 'a) -> int = # depth (1,[2,[];3,[]]);; - : int = 2 --------------------------------------------------------------------------- Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp JG ------------------- 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