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 QAA09076; Mon, 5 Jul 2004 16:36:59 +0200 (MET DST) 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 QAA09134 for ; Mon, 5 Jul 2004 16:36:58 +0200 (MET DST) Received: from kweetal.tue.nl (kweetal.tue.nl [131.155.3.6]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i65EavSH001483 for ; Mon, 5 Jul 2004 16:36:57 +0200 Received: by kweetal.tue.nl (Postfix, from userid 40) id F118E13B853; Mon, 5 Jul 2004 16:36:56 +0200 (CEST) Received: from winex2.campus.tue.nl (winex2.campus.tue.nl [131.155.70.169]) by kweetal.tue.nl (Postfix) with ESMTP id 909EF13B753 for ; Mon, 5 Jul 2004 16:36:48 +0200 (CEST) X-MimeOLE: Produced By Microsoft Exchange V6.0.6487.1 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: [Caml-list] Translation between datatypes with binding Date: Mon, 5 Jul 2004 16:36:48 +0200 Message-ID: <9F38CF35D80CAE409B979F3EB5242B4A014B1CCF@winex2.campus.tue.nl> Thread-Topic: Translation between datatypes with binding Thread-Index: AcRinYB4WUClyv8iREWH/EM0HBJ71A== From: "Jojgov, G.I." To: X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on kweetal.tue.nl X-Spam-DCC: : kweetal.tue.nl 1074; Body=1 Fuz1=1 Fuz2=1 X-Spam-Status: No, hits=-4.9 required=6.3 tests=BAYES_00 autolearn=ham version=2.63 X-Miltered: at concorde with ID 40E96789.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; datatypes:01 ideally:01 expr:01 expr:01 datatypes:01 behave:01 binders:01 reuse:01 ocaml:01 ocaml:01 int:01 int:01 rec:01 trivial:01 logical:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, I am relatively new to the OCAML programming, so my question may be trivial, but did not find related messages in the list archive and I would appreciate any tips.=20 I am trying to use OCAML as a logical framework to implement two systems with binding and to define a translation from one to the other. Ideally, I would like to be able to write code like this type expr1 =3D SomeValue1 of int | SomeBinder1 of int * (expr1 -> expr1);; type expr2 =3D=20 SomeValue2 of string | SomeBinder2 of string * (expr2 -> expr2);; let rec translate (term:expr1) : expr2 =3D match term with SomeValue1 x -> SomeValue2 (string_of_int x) | SomeBinder1 (x,body) -> SomeBinder2 ((string_of_int x),(function (v:expr2) -> (translate (body v)))) ;; (this is a simplified version of the real datatypes and the translation that I want to use) Of course, this code is not type-correct because "(function (v:expr2) -> (translate (body v)))" is not. If expr1 and expr2 could "behave" like classes I could have defined a common base class, say "expr", and then redefine the binders as ... SomeBinder1 of int * (expr -> expr1);; ... SomeBinder2 of string * (expr -> expr2);; and then the code would be "type-correct". My questions are: Is there a natural way to define a function like the translation function above on datatypes? Is there another way to implement these structures? I guess the only solution is to use classes, but I already have some code dealing with the two concrete types and preferably I would like to reuse the code. Thanks in advance for your comments, Georgi ------------------- 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