<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/12/c6d7410533306210d3b0d6368efaa0a8"
  from="Ker Lutyn &lt;ker527mail@y...&gt;"
  author="Ker Lutyn"
  date="2003-12-18T22:08:49"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml"
  prev="2003/12/7138ed0a510195951ecff784481773e2"
  next="2003/12/3329a866f131a44912f1f7b5588051b7"
  prev-thread="2003/12/c076c68f0465eb32ca1b6c1c4c4e4e4b"
  next-thread="2003/12/3329a866f131a44912f1f7b5588051b7"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
<msg 
  url="2003/12/c6d7410533306210d3b0d6368efaa0a8"
  from="Ker Lutyn &lt;ker527mail@y...&gt;"
  author="Ker Lutyn"
  date="2003-12-18T22:08:49"
  subject="Re: [Caml-list] Python&apos;s yield, Lisp&apos;s call-cc or C&apos;s setjmp/longjmp in OCaml">
</msg>
</thread>

<contents>
How about:

type 'a cont = Cont of ('a -&gt; 'a cont)

let apply c x = match c with Cont f -&gt; f x

let rec iterator c = function
  | Node l -&gt; List.fold_left iterator c l
  | Leaf x -&gt; apply c x

On Thu, Dec 18, 2003 at 10:14:19AM +0900, Nicolas Cannasse wrote:
&gt;
&gt; type 'a tree =
&gt;     |  Node of 'a tree list
&gt;     |  Leaf of 'a
&gt; 
&gt; let rec iterator = function
&gt;     | Node l -&gt; List.iter iterator l
&gt;     | Leaf x -&gt; yield x
&gt; 
&gt; Doing it using a closure is more difficult, since we need to reproduce the
&gt; stack using a data structure. That goes of course for all recursive data
&gt; 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

</contents>

</message>

