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 OAA13521; Tue, 6 Apr 2004 14:36:55 +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 OAA13528 for ; Tue, 6 Apr 2004 14:36:54 +0200 (MET DST) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from mwinf1001.wanadoo.fr (smtp10.wanadoo.fr [193.252.22.21]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i36CarYM023247 for ; Tue, 6 Apr 2004 14:36:53 +0200 Received: from vanicat.homelinux.org (ca-bordeaux-31-bdcst.w80-8.abo.wanadoo.fr [80.8.201.255]) by mwinf1001.wanadoo.fr (SMTP Server) with ESMTP id 109ED1C000A5 for ; Tue, 6 Apr 2004 14:36:53 +0200 (CEST) Received: from moi by vanicat.homelinux.org with local (Exim 4.31) id 1BAppI-0008Kd-67 for caml-list@inria.fr; Tue, 06 Apr 2004 14:37:12 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] Function forward declaration? References: <60532B15DF92FD4693AA89B2F7E01D8F013F29EC@tmex02> From: Remi Vanicat Mail-Copy-To: never Date: Tue, 06 Apr 2004 14:37:11 +0200 In-Reply-To: <60532B15DF92FD4693AA89B2F7E01D8F013F29EC@tmex02> (Timo Tapiola's message of "Tue, 6 Apr 2004 15:14:45 +0300") Message-ID: <87lll9wadk.dlv@vanicat.homelinux.org> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit 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; caml-list:01 recurrence:01 ocaml:01 rec:01 rec:01 writes:01 remi:01 remi:01 vanicat:01 vanicat:01 assert:02 unit:03 rarely:03 let:04 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 68 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. [...] -- Rémi Vanicat ------------------- 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