From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA23660 for caml-redistribution; Mon, 14 Jun 1999 17:48:17 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id MAA15662 for ; Mon, 14 Jun 1999 12:39:52 +0200 (MET DST) Received: from batman.npl.co.uk (batman.npl.co.uk [139.143.5.1]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id MAA18609 for ; Mon, 14 Jun 1999 12:39:50 +0200 (MET DST) Received: from herschel.npl.co.uk (unknown.npl.co.uk [139.143.1.16] (may be forged)) by batman.npl.co.uk (8.9.2/8.9.2) with ESMTP id LAA21956; Mon, 14 Jun 1999 11:39:45 +0100 (BST) Received: (from root@localhost) by herschel.npl.co.uk (8.8.5/8.8.5) id LAA03489; Mon, 14 Jun 1999 11:39:26 +0100 (BST) Received: by herschel.npl.co.uk XSMTPD/VSCAN; Mon, 14 Jun 1999 10:39:25 GMT Received: (from tm1@localhost) by squall.cise.npl.co.uk (8.8.8/8.8.8) id LAA24581; Mon, 14 Jun 1999 11:34:26 +0100 (BST) Date: Mon, 14 Jun 1999 11:34:26 +0100 (BST) From: Toby Moth Message-Id: <199906141034.LAA24581@squall.cise.npl.co.uk> To: caml-list@inria.fr, junzhang@ccrl.nj.nec.com Subject: Re: forward function definitions X-Sun-Charset: US-ASCII Sender: weis > 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 > 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