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
forward function definitions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 1999-06-14 (15:49)
From: Sven LUTHER <luther@m...>
Subject: Re: forward function definitions
On Wed, Jun 09, 1999 at 02:38:22PM -0400, Junbiao Zhang wrote:
> Hi,
> 	We're developing a fairly large system with multiple function
> definitions. It's inevitable that some functions may call other functions
> defined later(may not even be recursive calls as in the case of
> Sys.Signal_handle). My question is: how do I solve such a problem which is
> extremely trival in other languages?  Thanks. 

If the two functions are in different modules, just provide a interface file
for them, and it should work ok but can cause some linker problems.

2 clean way of doing this are :

* use the later called function as a parameter to the first called function :

  let register_signals_arg f =  Sys.signal Sys.sigalrm (Sys.Signal_handle f)

  let a sigid = ...
  let register_signals = register_signals_arg a
* Or you could define all this in the form of a module functor :

  module type XXX = sig val a : id -> ... end
  module Make_M (X : XXX) = struct
    let register_signals =  Sys.signal Sys.sigalrm (Sys.Signal_handle X.a)
  module ARG = struct 
    let a sigid = ...
  module M = Make_M ARG
  open M