Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2004-04-06 (12:47)
From: Correnson_Loïc <Loic.Correnson@t...>
Subject: Re: [Caml-list] Function forward declaration?
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
    However, you may loose polymorphism, if any, due to (_a ->_b) ref types.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: