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 UAA17780; Sun, 24 Aug 2003 20:02:22 +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 UAA17792 for ; Sun, 24 Aug 2003 20:02:18 +0200 (MET DST) Received: from relay.hoga.pl (res-61.hoga.pl [193.178.241.61] (may be forged)) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h7OI2Hf27446 for ; Sun, 24 Aug 2003 20:02:17 +0200 (MET DST) Received: from mail pickup service by relay.hoga.pl with Microsoft SMTPSVC; Sun, 24 Aug 2003 19:57:31 +0200 thread-index: AcNqajZhKXeARVQeR/i0N69ljs/Gyg== Content-Transfer-Encoding: 7bit Received: from ppp ([213.77.238.170]) by smtp.hoga.pl with InfocitySMTPReceiver (16.04.2002); Sun, 24 Aug 2003 20:04:45 +0200 Importance: normal Message-ID: <002c01c36a6a$05ba9f20$aaee4dd5@ppp> From: "Lukasz Stafiniak" To: Subject: [Caml-list] Polymorphic recursion Date: Sun, 24 Aug 2003 20:01:34 +0200 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0029_01C36A7A.84DF7FE0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 X-OriginalArrivalTime: 24 Aug 2003 17:57:31.0484 (UTC) FILETIME=[308811C0:01C36A69] X-Loop: caml-list@inria.fr X-Spam: no; 0.00; lukasz:01 recursion:01 recursion:01 evidently:01 ventured:99 typecheck:01 lukasz:01 jacques:01 caml-list:01 foo:01 foo:01 bug:01 jacques:01 caml-list:01 yli:99 X-Attachments: cset="iso-8859-2" type="application/octet-stream" name="typedcode.ml" name="typedcode.ml" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk This is a multi-part message in MIME format. ------=_NextPart_000_0029_01C36A7A.84DF7FE0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable Hi, I have recently encountered some very interesting notions (cited below). Although I've been using OCaml for some time, up to now I didn't know = about the existence of polymorphic records and (their reference to) the = problem of polymorphic recursion. Perhaps a word about it should be stated in the manual (more evidently)? (I don't even recall to have seen the syntax in = the manual for this.) With Your help I ventured again to "typecheck my programs before they = are generated" etc. But now I get an error I totally don't understand. = (Still it somehow resembles the problem it posed as an ordinary function.) Could someone explain? I have attached the file. Thanks in advance, Best wishes, Lukasz Jacques Garrigue Re: [Caml-list] Variant parameterized method? >>>>>>>>> This precise type is not admissible in the ocaml type system. In ocaml recursive types must be regular: only 'a foo may occur in the expansion of 'a foo. This problem is discussed in an answer to PR#1730 in the caml bug database. This can be solved by introducing an explicit wrapper. <<<<<<<<< Jacques Garrigue Re: [Caml-list] does class polymorphism need to be so complicated? >>>>>>>>> P.S. Having a lighter syntax for polymorphic methods might be a good idea. [...] An advantage of such a syntax is that it could also be used in normal "let rec" to provide polymorphic recursion. <<<<<<<<<< Uwaga! Do ko=F1ca sierpnia przed=B3u=BFyli=B6my promocje, do pakiet=F3w wielostanowiskowych dok=B3adamy PenDrive Sprawd=BC: http://www.mks.com.pl/promocja-mobile.html ------=_NextPart_000_0029_01C36A7A.84DF7FE0 Content-Type: application/octet-stream; name="typedcode.ml" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="typedcode.ml" =0A= (* this could be e.g.: type 'a annot =3D 'a code *)=0A= type 'a annot =3D 'a=0A= ;;=0A= =0A= type 'a valu =3D=0A= | Typeonly | Valu of 'a annot=0A= | Ord1bool of ('a, bool) ord1=0A= | Ord1int of ('a, int) ord1=0A= and ('a, 'b) ord1 =3D=0A= | Ord1Red of ('b -> 'a) valu=0A= | Ord2bool of ('a, 'b, bool) ord2=0A= | Ord2int of ('a, 'b, int) ord2=0A= and ('a, 'b, 'c) ord2 =3D=0A= | Ord2Red of ('a, 'c -> 'b) ord1=0A= ;;=0A= =0A= type typterm =3D=0A= | Tbool of bool valu=0A= | Tint of int valu=0A= ;;=0A= =0A= type 'a valu_env =3D {=0A= eValu : 'a annot list;=0A= eOrd1bool : ('a, bool) ord1_env option;=0A= eOrd1int : ('a, int) ord1_env option;=0A= }=0A= and ('a, 'b) ord1_env =3D {=0A= eOrd1Red : ('b -> 'a) valu_env option;=0A= eOrd2bool : ('a, 'b, bool) ord2_env option;=0A= eOrd2int : ('a, 'b, int) ord2_env option;=0A= }=0A= and ('a, 'b, 'c) ord2_env =3D {=0A= eOrd2Red : ('a, 'c -> 'b) ord1_env option;=0A= }=0A= ;;=0A= =0A= type env =3D {=0A= eBool : bool valu_env;=0A= eInt : int valu_env;=0A= }=0A= ;;=0A= =0A= type env_put_rec =3D {=0A= put_valu : 'a. 'a valu_env option -> 'a valu -> 'a valu_env;=0A= put_ord1 : 'a 'b. ('a, 'b) ord1_env option -> ('a, 'b) ord1 -> ('a,=0A= 'b)ord1_env;=0A= put_ord2 : 'a 'b 'c. ('a, 'b, 'c) ord2_env option -> ('a, 'b, 'c)=0A= ord2 -> ('a, 'b, 'c) ord2_env;=0A= }=0A= ;;=0A= =0A= let rec env_put =3D {=0A= put_valu =3D=0A= begin fun e ->=0A= let e =3D match e with=0A= | Some e -> e=0A= | None -> {eValu =3D []; eOrd1bool =3D None; eOrd1int =3D None}=0A= in=0A= function=0A= | Typeonly -> failwith "(Valu v) required"=0A= | Valu v ->=0A= {e with eValu =3D v::e.eValu}=0A= | Ord1bool tv ->=0A= {e with eOrd1bool =3D Some (env_put.put_ord1 e.eOrd1bool tv)}=0A= | Ord1int tv ->=0A= {e with eOrd1int =3D Some (env_put.put_ord1 e.eOrd1int tv)}=0A= end;=0A= put_ord1 =3D=0A= begin fun e ->=0A= let e =3D match e with=0A= | Some e -> e=0A= | None -> {eOrd1Red =3D None; eOrd2bool =3D None; eOrd2int =3D = None}=0A= in=0A= function=0A= | Ord1Red tv ->=0A= {e with eOrd1Red =3D Some (env_put.put_valu e.eOrd1Red tv)}=0A= | Ord2bool tv ->=0A= {e with eOrd2bool =3D Some (env_put.put_ord2 e.eOrd2bool tv)}=0A= | Ord2int tv ->=0A= {e with eOrd2int =3D Some (env_put.put_ord2 e.eOrd2int tv)}=0A= end;=0A= put_ord2 =3D=0A= begin fun e ->=0A= let e =3D match e with=0A= | Some e -> e=0A= | None -> {eOrd2Red =3D None}=0A= in=0A= function=0A= | Ord2Red tv ->=0A= {e with eOrd2Red =3D Some (env_put.put_ord1 e.eOrd2Red stages tv)}=0A= end;=0A= }=0A= ;;=0A= =0A= let env_put env =3D=0A= function=0A= | Tbool tv ->=0A= let v =3D env_put.put_valu env tv in=0A= {eBool =3D Some v; eInt =3D None}=0A= | Tint tv ->=0A= let v =3D env_put.put_valu env [Approx(id + env.stagevar,st)] tv in=0A= {eBool =3D None; eInt =3D Some v}=0A= ;;=0A= =0A= (* similar function env_get, etc. *)=0A= =0A= ------=_NextPart_000_0029_01C36A7A.84DF7FE0-- ------------------- 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