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:36)
From: Remi Vanicat <remi.vanicat@l...>
Subject: Re: [Caml-list] Function forward declaration? 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 Archives:
Bug reports: FAQ:
Beginner's list: