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 TAA06938; Tue, 6 Apr 2004 19:39:31 +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 TAA06944 for ; Tue, 6 Apr 2004 19:39:30 +0200 (MET DST) From: brogoff@speakeasy.net Received: from mail4.speakeasy.net (mail4.speakeasy.net [216.254.0.204]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i36HdSYM002657 for ; Tue, 6 Apr 2004 19:39:29 +0200 Received: (qmail 13422 invoked from network); 6 Apr 2004 17:39:27 -0000 Received: from grace.speakeasy.net ([216.254.0.22]) (envelope-sender ) by mail4.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 6 Apr 2004 17:39:27 -0000 Date: Tue, 6 Apr 2004 10:39:26 -0700 (PDT) To: =?iso-8859-1?Q?Correnson_Lo=EFc?= cc: Timo.Tapiola@tietoenator.com, Ocaml Subject: Re: [Caml-list] Function forward declaration? In-Reply-To: <00cf01c41bd6$391b53a0$0203a8c0@hoedic> Message-ID: References: <60532B15DF92FD4693AA89B2F7E01D8F013F29EC@tmex02> <00cf01c41bd6$391b53a0$0203a8c0@hoedic> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN Content-Transfer-Encoding: QUOTED-PRINTABLE X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; brogoff:01 caml-list:01 struct:01 failwith:01 struct:01 recursion:01 faq:01 compiler:01 caml:01 mutable:01 speakeasy:01 polymorphic:01 refs:02 refs:02 module:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 78 On Tue, 6 Apr 2004, [iso-8859-1] Correnson Lo=EFc wrote: > b) You can also define *real* forward function by using references (alrea= dy > suggested) > However, you may loose polymorphism, if any, due to (_a ->_b) ref typ= es. You may sidestep this issue by rolling your own refs using the explicit polymorphism on record fields, sketched below: type fwd_ref =3D { mutable f : 'a 'b . 'a -> 'b } module Module1 =3D struct let forward_g =3D { f =3D (fun x -> failwith "forward_g") } let f =3D forward_g.f end module Module2 =3D struct let g =3D Module1.f let _ =3D Module1.forward_g.f <- g end and of course you can make it as pretty (yeah, I know, dressing up a pig) as refs if you wish. There was a discussion of this a looooong time ago, in the context of suppo= rting polymorphic recursion in the language, and I believe it was mentioned that = some experimental Caml compiler had a forward declaration capability. It seems l= ike a good idea, and I wonder why it hasn't made it into the language, as this is= a FAQ and a language blemish. -- 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