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 CAA29025; Wed, 24 Mar 2004 02:41:34 +0100 (MET) 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 CAA28705 for ; Wed, 24 Mar 2004 02:41:33 +0100 (MET) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i2O1g1KW016124 for ; Wed, 24 Mar 2004 02:42:03 +0100 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 KAA11584; Wed, 24 Mar 2004 10:41:18 +0900 (JST) To: skaller@users.sourceforge.net Cc: caml-list@inria.fr Subject: Re: [Caml-list] extensible records again In-Reply-To: <1080069240.4708.39.camel@pelican.wigram> References: <1079926276.3165.49.camel@pelican.wigram> <20040322055430.A45C89BBA2@orchestra.cs.caltech.edu> <1080069240.4708.39.camel@pelican.wigram> 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: <20040324104118K.garrigue@kurims.kyoto-u.ac.jp> Date: Wed, 24 Mar 2004 10:41:18 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 extensible:01 jacques:01 sourceforge:01 failwith:01 wwwfun:01 extensible:01 datatypes:01 partition:01 'pat:99 expr:01 'pat:99 functors:01 recursion:01 struct:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 343 From: skaller > At the moment you can do this: > > type x = [`A | `B ] > type y = [x | `C ] > > so that y is a subtype (extension) of x. > > You can even match: > > match aY with > | #x as xv -> xv > | _ -> failwith "Not an x" > > to reduce aY to an x. [...] Let me just add a pointer to the concrete description of how you can do this with recursive types: http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/papers/fose2000.html It describes in detail the steps to build extensible recursive datatypes. > In Felix, I want to partition expressions, types, > patterns, statements, and a few other kinds of terms > into one or more classes and use some combinations > of these: but all these terms are mutually recursive: > statements can contain expressions and types and patterns, > patterns have 'when' expressions, types may contain > "typeof(expression)" as a type, and statements can > be considered as expressions.. > > So I end up with a rather large number of parameters > on each of the fine grained components I want to combine: > something like: > > type 'expr 'typ 'pat 'stat expr1 = .... > ... > type 'expr 'typ 'pat 'stat typ1 = ... > ... The mixin2.ml code on the above page gives an example of you can do it using classes. Note that this solves only the problem for functions, not for types. Another approach, which could maybe solve the problem with type parameters, would be to use recursive modules: define all your sublanguages as functors, and close the recursion with a recursive module definition. Recursive modules are a new feature in ocaml 3.07, but I think they can help for such problems. However, there is a difficulty, as all modules in a recursive definition must have an explicit signature, and the language of module types seems to be weaker than the language of modules. The fact one has to duplicate all type definitions is bothering too. > type x = [`A of +x | `B ] > type y = [x | `C ] might be encoded as module type Xrec = sig type t end module X0(Xrec : Xrec) = struct type t0 = Xrec.t type t = [`A of t0 | `B] end module type Xsig = sig type t0 type t = [`A of t0 | `B] end module rec X : (Xsig with type t0 = X.t) = X0(X) module Y0(Xrec : Xrec) = struct module XY = X0(Xrec) type t0 = Xrec.t type t = [XY.t | `C] end module type Ysig = ??? module rec Y : (Xsig with type t0 = Y.t) = Y0(Y) 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