From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr>
To: james woodyatt <jhw@wetware.com>
Cc: Tyler Eaves <tyler@ml1.net>, caml-list@inria.fr
Subject: Re: [Caml-list] A (much less) frustrated beginner
Date: Wed, 24 Dec 2003 09:53:55 +0100 [thread overview]
Message-ID: <16361.21539.611872.267074@gargle.gargle.HOWL> (raw)
In-Reply-To: <48E3FF15-35DC-11D8-859D-000393B8133A@wetware.com>
james woodyatt writes:
>
> For extra credit, have a look at the following bit of weirdness
> (though, I really think this thread belongs on the ocaml-beginners
> list). I think you will be surprised at how fast it runs, and I
> suspect it would be a good piece of example code for figuring out how
> 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
[< 'n; s >] -> if p n then [< 'n; filter p s >] else [< filter p s >]
let naturals = let rec gen n = [< 'n; gen (succ n) >] in gen 2
let primes =
let rec sieve = parser
[< 'n; s >] -> [< 'n; sieve (filter (fun m -> m mod n <> 0) s) >]
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
prev parent reply other threads:[~2003-12-24 8:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-23 19:00 Tyler Eaves
2003-12-23 21:13 ` Aleksey Nogin
2003-12-24 1:04 ` Nicolas Cannasse
2003-12-24 6:23 ` Sven Luther
2003-12-24 6:42 ` james woodyatt
2003-12-24 8:53 ` Jean-Christophe Filliatre [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16361.21539.611872.267074@gargle.gargle.HOWL \
--to=jean-christophe.filliatre@lri.fr \
--cc=caml-list@inria.fr \
--cc=jhw@wetware.com \
--cc=tyler@ml1.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox