Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] [ANN] The Missing Library
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] [ANN] The Missing Library
On Thu, 2004-04-29 at 15:04, Jon Harrop wrote:
> 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.

CPS transform?


> I don't know. I just brush my hands over the keyboard and programs come 
> out. :-)

teach me your technique! When I do that, i just get bugs leaping out!

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net



-------------------
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