Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: forward function definitions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Toby Moth <tm1@c...>
Subject: Re: forward function definitions

> From Pierre.Weis@inria.fr Sat Jun 12 00:13:57 1999
> Date: Wed, 9 Jun 1999 14:38:22 -0400 (EDT)
> From: Junbiao Zhang <junzhang@ccrl.nj.nec.com>
> X-Sender: junzhang@flame
> To: caml-list@inria.fr
> Subject: forward function definitions
> MIME-Version: 1.0
> Sender: Pierre.Weis@inria.fr
> 
> 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. 
> 

Can't you just wrap up your deferred functions inside a mutable array or
an object ?

e.g. 

type 'a defer = { mutable exec : 'a }

let defer_fun = { exec = fun i -> print_int i }

let eval = defer_fun.exec;;

eval 3;;
defer_fun.exec <- fun i -> print_int ( i * 2 );;
eval 3;;

etc.
or

class defer = 
  object
    val mutable exec = fun i -> print_int i
    method update new_fun = exec <- new_fun
    method exec = exec
  end

....

I picked types here that match the types used in your example.

t