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 OAA10107; Tue, 6 Apr 2004 14:14:54 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA09872 for ; Tue, 6 Apr 2004 14:14:53 +0200 (MET DST) From: Timo.Tapiola@tietoenator.com Received: from datnt07.tieto.com (mail1.tieto.com [194.110.47.24]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i36CFijq000504 for ; Tue, 6 Apr 2004 14:15:44 +0200 Received: by datnt07.tieto.com with Internet Mail Service (5.5.2657.72) id ; Tue, 6 Apr 2004 15:14:47 +0300 Message-ID: <60532B15DF92FD4693AA89B2F7E01D8F013F29EC@tmex02> To: caml-list@inria.fr Subject: [Caml-list] Function forward declaration? Date: Tue, 6 Apr 2004 15:14:45 +0300 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2657.72) Content-Type: text/plain X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; funct:01 expr:01 expr:01 bin:01 bin:01 func:01 func:01 bool:01 bool:01 ocaml:01 int:01 int:01 rec:01 rec:01 binary:02 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 66 Hi, could someone tell me if there is some way to forward declare functions in OCaml? Code example, some parts of code removed: ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -------------- let evaluate_funcall funsig = let func = Funspace.get_funref funsig in match !func with Funct(s, block) -> interpret_block block; ValNone ;; ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -------------- let rec evaluate_expr expr = match expr with ExpInt(int) -> ValInt(int) | ExpFloat(float) -> ValFloat(float) | ExpString(str) -> ValString(str) | ExpBool(bool) -> ValBool(bool) | ExpVar(var) -> let varval = Varspace.get_varvalue var in if varval = ValNone then raise (Interpret_error("Error: variable not declared.\n")) else varval | ExpBinary(ex1, bin, ex2) -> let value1 = evaluate_expr ex1 in let value2 = evaluate_expr ex2 in evaluate_binary value1 bin value2 | ExpUnary(un, ex) -> let value1 = evaluate_expr ex in evaluate_unary un value1 | ExpCast(vartype, ex) -> let value = evaluate_expr ex in evaluate_cast vartype value | ExpFunCall(funsig) -> evaluate_funcall funsig ;; ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -------------- let interpret_phrase phrase = match phrase with PhrExpression(exp) -> evaluate_expr exp; () | PhrStatement(stmt) -> interpret_stmt stmt | PhrCommand(cmd) -> interpret_cmd cmd; ;; ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -------------- let rec interpret_phrases phrases = match phrases with [] -> () | p::r -> interpret_phrase p; interpret_phrases r ;; ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -------------- let interpret_block block = match block with Block([]) -> () | Block(phrases) -> interpret_phrases phrases ;; ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -------------- Call path starting from function interpret_block: interpret_block interpret_phrases interpret_phrase interpret_expr evaluate_funcall interpret_block How should I deal with this situation if there is no way to forward declare functions? Thanks in advance, Timo ------------------- 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