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 OAA15653; Tue, 6 Apr 2004 14:54:05 +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 OAA15284 for ; Tue, 6 Apr 2004 14:54:04 +0200 (MET DST) Received: from pop19.ucdavis.edu (pop19.ucdavis.edu [169.237.105.29]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i36Cs2YM025608 for ; Tue, 6 Apr 2004 14:54:03 +0200 Received: from mallorn (mallorn.ucdavis.edu [128.120.141.141]) by pop19.ucdavis.edu (8.12.10/8.12.9/it-std-5.2.0) with SMTP id i36Cs1iI013948 for ; Tue, 6 Apr 2004 05:54:01 -0700 (PDT) Received: by mallorn (sSMTP sendmail emulation); Tue, 6 Apr 2004 06:00:10 -0700 From: "Issac Trotts" Date: Tue, 6 Apr 2004 06:00:10 -0700 To: caml-list@inria.fr Subject: Re: [Caml-list] Function forward declaration? Message-ID: <20040406130010.GA29623@mallorn> Mail-Followup-To: ijtrotts@ucdavis.edu, caml-list@inria.fr References: <60532B15DF92FD4693AA89B2F7E01D8F013F29EC@tmex02> <87lll9wadk.dlv@vanicat.homelinux.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87lll9wadk.dlv@vanicat.homelinux.org> User-Agent: Mutt/1.5.5.1+cvs20040105i 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; issac:01 trotts:01 ijtrotts:01 caml-list:01 2004:99 recurrence:01 issac:01 trotts:01 ijtrotts:01 ocaml:01 rec:01 rec:01 0200,:01 writes:01 remi:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 70 On Tue, Apr 06, 2004 at 02:37:11PM +0200, Remi Vanicat wrote: > Timo.Tapiola@tietoenator.com writes: > > > Hi, > > > > could someone tell me if there is some way to forward declare functions in > > OCaml? > > no, but you can : > > use the "let rec ... and .. and ... " construct : > > let rec simpl1 x y = simpl2 y x > and simpl2 x y = simpl1 y x > > or use local function : > > let rec simpl1 x y = > let simpl2 x y = simpl1 y x in > simpl2 y x > > You can even use both technique at the same time. > > The third technique is less clean, and is rarely needed : it use > references : > > let simpl1_ref = ref (fun x -> assert false) > > let simpl2 x y = !simpl1_ref y x > let simpl1 x y = simpl2 x y > let _ = simpl1_ref := simpl1 > > both two first method cover most of the case, the third one is needed > only in very long code, or in recurrence between compilation unit. This cleaner alternative should cover some of those cases: let simpl2 f x y = f y x let rec simpl1 x y = simpl2 simpl1 x y -- Issac Trotts http://mallorn.ucdavis.edu/~ijtrotts (w) 530-757-8789 ------------------- 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