Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] OCaml popularity
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Daniel M. Albro <albro@h...>
Subject: Re: [Caml-list] OCaml popularity

	Well, I'm certainly learning a lot this way, anyway...
Might be useful stuff for a tutorial!  This continuation-
passing style here runs quite fast, by the way -- equivalent to the
original exception-for-loop suggestion:

real    0m30.056s
user    0m29.950s
sys     0m0.100s

On Fri, 2003-03-14 at 01:05, Ville-Pertti Keinonen wrote:
> > Break simulated by continuation passing (I think that's
> > what this is -- it looks like a call/cc to me, anyway)
> 
> Sort of, except that the continuation can't be used outside the 
> function called by escape.  Here's a different approach (this is 
> essentially a variation of the recursive style, because you need to 
> make sure the continuation is called as a tail call):
> 
> let _ =
>    let ary = [| 1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12 |] in
>    let rec loop f j =
>      if j = 10 || ary.(j) = 5 then f ()
>      else loop f (j + 1)
>    in
>      let rec outer i =
>        if i <= 1_000_000_000 then
>          loop (fun _ -> outer (i + 1)) 0
>      in
>        outer 1
> 
> This style is useful in some cases when you can write a significant 
> part of your program using continuations.
-- 
Daniel M. Albro <albro@humnet.ucla.edu>

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