<?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/64fa006e243b740a6a8ada2542e92b5c"
  from="Jean-Christophe Filliatre &lt;Jean-Christophe.Filliatre@l...&gt;"
  author="Jean-Christophe Filliatre"
  date="2003-12-24T08:59:59"
  subject="Re: [Caml-list] A (much less) frustrated beginner"
  prev="2003/12/68fb62727bb19539682c9f2f2f52efda"
  next="2003/12/66a8d5c3e00e6eaf74c7910304840b3f"
  prev-in-thread="2003/12/60a121b77b89d2c770a1594f0eefeb64"
  prev-thread="2003/12/6f29bbcbd7940b1f3bee84f95924c267"
  next-thread="2003/12/68fb62727bb19539682c9f2f2f52efda"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] A (much less) frustrated beginner">
<msg 
  url="2003/12/0669d0f53998ae1f3b5da005b4fd9200"
  from="Tyler Eaves &lt;tyler@m...&gt;"
  author="Tyler Eaves"
  date="2003-12-23T18:58:56"
  subject="[Caml-list] A (much less) frustrated beginner">
<msg 
  url="2003/12/d532f069cb0e2459bc1c0974c321c7b3"
  from="Aleksey Nogin &lt;aleksey@n...&gt;"
  author="Aleksey Nogin"
  date="2003-12-23T21:13:54"
  subject="Re: [Caml-list] A (much less) frustrated beginner">
</msg>
<msg 
  url="2003/12/5523210d21c4e1436e65cb86585dda2e"
  from="Nicolas Cannasse &lt;warplayer@f...&gt;"
  author="Nicolas Cannasse"
  date="2003-12-24T01:05:01"
  subject="Re: [Caml-list] A (much less) frustrated beginner">
<msg 
  url="2003/12/dc3cc05d859914889409e9a3c96de1e9"
  from="Sven Luther &lt;sven.luther@w...&gt;"
  author="Sven Luther"
  date="2003-12-24T06:23:42"
  subject="Re: [Caml-list] A (much less) frustrated beginner">
</msg>
</msg>
<msg 
  url="2003/12/60a121b77b89d2c770a1594f0eefeb64"
  from="james woodyatt &lt;jhw@w...&gt;"
  author="james woodyatt"
  date="2003-12-24T06:42:13"
  subject="Re: [Caml-list] A (much less) frustrated beginner">
<msg 
  url="2003/12/64fa006e243b740a6a8ada2542e92b5c"
  from="Jean-Christophe Filliatre &lt;Jean-Christophe.Filliatre@l...&gt;"
  author="Jean-Christophe Filliatre"
  date="2003-12-24T08:59:59"
  subject="Re: [Caml-list] A (much less) frustrated beginner">
</msg>
</msg>
</msg>
</thread>

<contents>

james woodyatt writes:
 &gt; 
 &gt; For extra credit, have a look at the following bit of weirdness 
 &gt; (though, I really think this thread belongs on the ocaml-beginners 
 &gt; list).  I think you will be surprised at how fast it runs, and I 
 &gt; suspect it would be a good piece of example code for figuring out how 
 &gt; to use lazy evaluation in Ocaml.

Here  is another using  streams (thus  you need  to compile  with "-pp
camlp4o"). It's  a nice example to  learn about streams,  though it is
not that efficient.
-- 
Jean-Christophe

======================================================================
let rec filter p = parser
  [&lt; 'n; s &gt;] -&gt; if p n then [&lt; 'n; filter p s &gt;] else [&lt; filter p s &gt;]

let naturals = let rec gen n = [&lt; 'n; gen (succ n) &gt;] in gen 2

let primes =
  let rec sieve = parser
    [&lt; 'n; s &gt;] -&gt; [&lt; 'n; sieve (filter (fun m -&gt; m mod n &lt;&gt; 0) s) &gt;]
  in
  sieve naturals

let _ = 
  while true do
    Printf.printf "%d\n" (Stream.next primes); flush stdout;
  done
======================================================================

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

