Re: forward function definitions

From: Toby Moth (tm1@cise.npl.co.uk)
Date: Mon Jun 14 1999 - 12:34:26 MET DST


Date: Mon, 14 Jun 1999 11:34:26 +0100 (BST)
From: Toby Moth <tm1@cise.npl.co.uk>
Message-Id: <199906141034.LAA24581@squall.cise.npl.co.uk>
To: caml-list@inria.fr, junzhang@ccrl.nj.nec.com
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



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:23 MET