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 OAA14875; Tue, 6 Apr 2004 14:47:03 +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 OAA14867 for ; Tue, 6 Apr 2004 14:47:02 +0200 (MET DST) Received: from mailhost.trusted-logic.fr (mailhost.trusted-logic.fr [194.250.150.5]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i36Cl0YM024697 for ; Tue, 6 Apr 2004 14:47:01 +0200 Received: from wight.trusted-logic.fr (wight.trusted-logic.fr [192.168.1.210]) by mailhost.trusted-logic.fr (Postfix) with ESMTP id 1BE231E9; Tue, 6 Apr 2004 14:47:00 +0200 (CEST) Received: from hoedic (hoedic.trusted-logic.fr [192.168.3.2]) by wight.trusted-logic.fr (Postfix) with SMTP id 02536713C0; Tue, 6 Apr 2004 14:47:00 +0200 (CEST) Message-ID: <00cf01c41bd6$391b53a0$0203a8c0@hoedic> From: =?iso-8859-1?Q?Correnson_Lo=EFc?= To: Cc: "Ocaml" References: <60532B15DF92FD4693AA89B2F7E01D8F013F29EC@tmex02> Subject: Re: [Caml-list] Function forward declaration? Date: Tue, 6 Apr 2004 14:53:56 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 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 expr:01 expr:01 rec:01 rec:01 modules:02 complex:03 recursive:03 recursive:03 tracing:03 types:03 let:04 let:04 parameter:04 functions:05 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 69 Hi, Of course you may use mutually recursive functions, but it is not always easy when you must use forward declarations between different modules. It would be especially the case when writing complex interpreters (as yours ?). You may use two tips & trickes to resolve such forward definitions : a) You can use an extra parameter to handle recursive calls: let evaluate_expr eval_fun_rec expr = [...] (** use eval_fun_rec instead of evaluate_funcall **) let evaluate_stmt eval_fun_rec stmt = [...] (** use (evaluate_expr eval_fun_rec) **) let rec evaluate_funcall = [...] evaluate_expr evaluate_funcall expression [...] better: you may pack several callback-functions into a record. Additionnaly, this technique allow to insert *easily* tracing in/out or debuging functions etc. b) You can also define *real* forward function by using references (already suggested) However, you may loose polymorphism, if any, due to (_a ->_b) ref types. LC. ------------------- 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