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: -- (:)
From: Basile Starynkevitch <basile.starynkevitch@i...>
Subject: Re: [Caml-list] Function forward declaration?
On Wed, Apr 07, 2004 at 03:15:19PM +0100, Richard Jones wrote:
> The trouble seems to be that I have a perfectly practical and
> reasonable desire to see prototypes added to the language, because,
> believe it or now, it helps to solve some problems in the Real World.
> Now if there's some deep reason why it's actually impossible I would
> understand, but plenty of other languages (eg. C) seem to have
> prototypes and they get along just fine.

What I understand you call prototypes are signature items (or I
misunderstood your point). You can have use signatures and modules,
either by compiling both foo.mli & (with the prototypes in
foo.mli & the implementations in or by having, inside your
compilation unit, a signature (or module type) and an structure (or


> (Same, by the way, goes for a 'return' statement which OCaml is crying
> out for).

For your information, the revised syntax (provided by camlp4) does
have (IIRC) a return keyword (but I don't remember more, and I never
used it).

Regarding this thread, a useful trick (somehow a hack, but used in the
compiler itself) is to declare a reference to a function initialised
to a function throwing an exception:

   (** in foo.mli *)

   val rf: (int -> string) ref

   (** in *)

   let rf = ref ((fun x -> failwith "rf not yet implemented") 
                : (int -> string))

   (* in a *)

   Foo.rf := (fun x -> Printf.sprintf "the real rf %d" x);;

this trick is needed e.g. when two modules are mutually recursive, eg
if a function of foo calls a function of bar which calls the first
function of foo. (In the compiler, you can find such an instance -
Env;check_modtyping_inclusion is a reference to
Includemod.check_modtype_inclusion - in directory caml/typing/ )

Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr
Project - INRIA Rocquencourt --- all opinions are only mine 

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