From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA20867; Wed, 24 Dec 2003 09:59:59 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id JAA20914 for ; Wed, 24 Dec 2003 09:59:57 +0100 (MET) Received: from lri.lri.fr (lri.lri.fr [129.175.15.1]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id hBO8xvb10346 for ; Wed, 24 Dec 2003 09:59:57 +0100 (MET) Received: from pc8-123 (pc8-123 [129.175.8.123]) by lri.lri.fr (8.12.10/jtpda-5.4) with ESMTP id hBO8ruUV028035 ; Wed, 24 Dec 2003 09:53:56 +0100 (MET) Received: from filliatr by pc8-123 with local (Exim 3.35 #1 (Debian)) id 1AZ4mB-0000Y8-00; Wed, 24 Dec 2003 09:53:55 +0100 From: Jean-Christophe Filliatre MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16361.21539.611872.267074@gargle.gargle.HOWL> Date: Wed, 24 Dec 2003 09:53:55 +0100 To: james woodyatt Cc: Tyler Eaves , caml-list@inria.fr Subject: Re: [Caml-list] A (much less) frustrated beginner In-Reply-To: <48E3FF15-35DC-11D8-859D-000393B8133A@wetware.com> References: <1072206032.62516.27.camel@tylere> <48E3FF15-35DC-11D8-859D-000393B8133A@wetware.com> X-Mailer: VM 7.03 under Emacs 20.7.2 Reply-To: Jean-Christophe.Filliatre@lri.fr (Jean-Christophe Filliatre) X-MailScanner: Found to be clean X-Loop: caml-list@inria.fr X-Spam: no; 0.00; filliatre:01 filliatre:01 lri:01 caml-list:01 woodyatt:01 weirdness:01 figuring:01 -pp:01 camlp:01 naturals:01 primes:01 naturals:01 printf:01 printf:01 primes:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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