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 XAA17138; Fri, 9 Jan 2004 23:24:24 +0100 (MET) 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 XAA17738 for ; Fri, 9 Jan 2004 23:24:22 +0100 (MET) Received: from mail5.speakeasy.net (mail5.speakeasy.net [216.254.0.205]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id i09MOL501483 for ; Fri, 9 Jan 2004 23:24:21 +0100 (MET) Received: (qmail 17851 invoked from network); 9 Jan 2004 22:24:18 -0000 Received: from grace.speakeasy.net ([216.254.0.22]) (envelope-sender ) by mail5.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 9 Jan 2004 22:24:18 -0000 Date: Fri, 9 Jan 2004 14:24:16 -0800 (PST) From: brogoff@speakeasy.net To: =?ISO-8859-1?Q?Daniel_B=FCnzli?= cc: Jean-Christophe Filliatre , Subject: Re: [Caml-list] Encoding existential types without modules In-Reply-To: <286C1B71-42EA-11D8-A280-000393DBC266@epfl.ch> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN Content-Transfer-Encoding: QUOTED-PRINTABLE X-Loop: caml-list@inria.fr X-Spam: no; 0.00; brogoff:01 caml-list:01 existential:01 recursion:01 recursion:01 jacques:01 3.07:01 datatype:01 val:01 val:01 struct:01 unpacking:01 struct:01 ocaml:01 speakeasy:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Fri, 9 Jan 2004, [ISO-8859-1] Daniel B=FCnzli wrote: > Thanks for your feedback. > > Besides, I would just like to point out that the way I solved the > problem of polymorphic recursion for the apply function in the example > of the list of composable function cannot be applied in general. > > A general way to solve the problem of polymorphic recursion was given > by Brian Rogoff in a previous post [1]. Applying this solution gives > the following (much simpler and maybe more efficient) code. I blame Jacques Garrigue for that trick! He is entitled to transfer the bla= me to whomever he chooses. ;-) You may also want to consider using the recursive module feature introduced= in OCaml 3.07 for this too. Unfortunately, you can't (yet, Xavier says he's working on it) apply it directly to Funlist on account of your nil. That w= ould be best, but by wrapping apply I think you can do it like so: module Funlist : sig (* The funlist datatype *) type ('a, 'b) t (* Constructors *) val nil : ('a, 'a) t val cons : ('a -> 'b) -> ('b, 'c) t -> ('a, 'c) t (* Applying a value to a composition *) val apply : ('a, 'b) t -> 'a -> 'b end =3D struct (* List of composable functions. The intended type expressed by the four types below is : type ('a, 'b) t =3D Nil of ('a -> 'b) | Cons of exists 'c. ('a -> 'c) * ('c, 'b) t *) type ('a, 'b) t =3D Nil of ('a -> 'b) | Cons of ('a, 'b) packed_list and ('a, 'b, 'z) list_scope =3D { bind_list : 'c. ('a -> 'c) * ('c, 'b) = t -> 'z} and ('a, 'b) packed_list =3D { open_list : 'z. ('a, 'b, 'z) list_scope -= > 'z } (* Packing and unpacking lists *) let pack_list h t =3D { open_list =3D fun scope -> scope.bind_list (h,t)= } let with_packed_list p e =3D p.open_list e (* Constructors *) let nil =3D Nil(fun x -> x) let cons h t =3D Cons(pack_list h t) module rec PolyRec : sig val apply : ('a, 'b) t -> 'a -> 'b end =3D struct let apply l x =3D match l with | Nil id -> id x | Cons l -> with_packed_list l { bind_list =3D function h,t -> PolyRec.apply t (h x) } end let apply =3D PolyRec.apply end -- Brian ------------------- 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