From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id HAA17997; Thu, 29 Apr 2004 07:08:20 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id HAA17990 for ; Thu, 29 Apr 2004 07:08:19 +0200 (MET DST) Received: from ptb-relay03.plus.net (ptb-relay03.plus.net [212.159.14.214]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i3T58IYM031568 for ; Thu, 29 Apr 2004 07:08:18 +0200 Received: from [80.229.56.224] (helo=chetara) by ptb-relay03.plus.net with esmtp (Exim) id 1BJ3mU-0002Ja-CL for caml-list@inria.fr; Thu, 29 Apr 2004 05:08:18 +0000 From: Jon Harrop Organization: University of Cambridge To: caml-list Subject: Re: [Caml-list] [ANN] The Missing Library Date: Thu, 29 Apr 2004 06:04:13 +0100 User-Agent: KMail/1.5.4 References: <200404290256.24399.jdh30@cam.ac.uk> <1083207649.9537.1250.camel@pelican.wigram> In-Reply-To: <1083207649.9537.1250.camel@pelican.wigram> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200404290604.13189.jdh30@cam.ac.uk> X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 2004:99 2004:99 supplier:99 supplier:99 implemented:01 verbose:01 recursion:01 mechanically:01 callback:01 gui:01 widgets:01 callback:01 mutable:01 mutable:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thursday 29 April 2004 4:00 am, skaller wrote: > On Thu, 2004-04-29 at 11:56, Jon Harrop wrote: > > Can you give me a simple example where you are forced to use mutable > > state? > ... > The inverse is a supplier of list elements: > > let make_supplier lst = > let lst = ref lst in > let get () = function > > | h :: t -> lst :=t; h > | [] -> raise Not_found But can't this be implemented without mutable state as: let make_supplier lst = let rec get lst () = match lst with [] -> raise Not_found | h::t -> (h, fun () -> get t ()) in get lst so it returns the next element and a function to "supply" the rest. > ... > let iter f = function > | h::t -> f h; iter f t > | [] ->() > > This is the desirable form. Why is that desirable? To me, it looks as though this form is necessarily more verbose and, therefore, undesirable. > Traditionally, algorithms had to be factored > so one of the cooperating pair of routines > had to be unnatural: one had to be master, > and the other slave. Is mutual recursion not an example of having two "master" functions. > Felix control inverts arbitrary procedural code > mechanically: that is, you write code that reads > data and it is translated into a callback. What is your favourite example of this code morphing being useful? > Wouldn't you rather program an *active* agent > for your complex GUI widgets that a passive callback > driven one? I don't know. I just brush my hands over the keyboard and programs come out. :-) Cheers, Jon. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners