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 01:18, John Goerzen wrote:
> On Wed, Apr 28, 2004 at 09:24:43PM +1000, skaller wrote:
> > On Wed, 2004-04-28 at 19:18, Jon Harrop wrote:
> > Control inversion. In Ocaml you can write:
> > 
> > List.iter (fun x -> print_endline x) ["Hello"; "World"];;
> 
> [ snip ]
> 
> > while ( p != e) do print_endline (get p); incr p done;
>  [ snip ]
> > 
> > The List.iter style HOF is very limited in utility
> > in a functional language: there is no state.
> 
> > In Ocaml you can add state of course. But it's a mess.
> 
> I don't find it all that problematic.  

Compare:

let count = ref 0 in
List.iter
(fun x -> 
  if !start = 0 then 
  (start := 1; print "["; print x; )
  else (print ";"; print x)
)
lst; 
if (!start <> 0) then print "]"

and please don't tell me that isn't a total mess compared with

proc print_list(){
  read x;
  if x == None goto empty;
  print "["
next:>
  print x;
  read x;
  if x == None goto endoff;
  print ";"; 
  goto next:
endoff:> 
  print "]"
empty:
}

Notice there are NO FLAGS. The entire state
is represented by the program counter.
In a more complex problem, the entire
state can be local. You can even write
a recursive procedure .. that builds a list  ..
or even a tree .. do you want modify 
the external state like that, building
a data structure to *emulate* a stack
when you can actually have a real one?

By the way this is valid, executable Felix.
And of course it works behind the scenes
by emulating a stack :D

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