Browse thread
Re: [Caml-list] Python's yield, Lisp's call-cc or C's setjmp/longjmp in OCaml
- Ker Lutyn
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2003-12-18 (22:08) |
From: | Ker Lutyn <ker527mail@y...> |
Subject: | Re: [Caml-list] Python's yield, Lisp's call-cc or C's setjmp/longjmp in OCaml |
How about: type 'a cont = Cont of ('a -> 'a cont) let apply c x = match c with Cont f -> f x let rec iterator c = function | Node l -> List.fold_left iterator c l | Leaf x -> apply c x On Thu, Dec 18, 2003 at 10:14:19AM +0900, Nicolas Cannasse wrote: > > type 'a tree = > | Node of 'a tree list > | Leaf of 'a > > let rec iterator = function > | Node l -> List.iter iterator l > | Leaf x -> yield x > > Doing it using a closure is more difficult, since we need to reproduce the > stack using a data structure. That goes of course for all recursive data > structures. __________________________________ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ ------------------- 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