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: Ville-Pertti Keinonen <will@e...>
Subject: Re: [Caml-list] OCaml popularity

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

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