Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Function forward declaration?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Correnson_Loïc <Loic.Correnson@t...>
Subject: Re: [Caml-list] Function forward declaration?
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