From mboxrd@z Thu Jan 1 00:00:00 1970 To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu> Subject: Re: [9fans] Concurrency and message passing with Newsqueak In-reply-to: Your message of "Tue, 22 May 2007 11:32:35 PDT." <3e1162e60705221132p529b0ec6qf802e84374577cec@mail.gmail.com> From: Bakul Shah Date: Tue, 22 May 2007 16:34:40 -0700 Message-Id: <20070522233441.068EE5B3E@mail.bitblocks.com> Topicbox-Message-UUID: 709c0cfc-ead2-11e9-9d60-3106f5b1d025 > > http://en.literateprograms.org/Sieve_of_Eratosthenes_%28Haskell%29 > I'm not sure that's even valid Haskell though. Looks like two type > definitions for the same function, and even if you correct that I > don't think it produces what one might think it does. At least not on > GHC :-) The second type definition on the referred page is not needed (actually you don't need either defn). The function works but you have to give it [2..], all natural numbers >= 2. The prime sieve definition I like most is this: sieve (a:xs) = a:sieve [x | x<- xs, x `mod` a > 0] primes = sieve [2..] Now you can just do 100 `take` primes to get first 100 primes. A stream such as primes will (and must) return the same Nth value every time so after computing a value it will be cached for later. A stream in effect has storage proportional to the number of cdr (i.e. tail) operations done on it. A channel on the other hand needs fixed minimum storage to affect one value transfer and it has no memory of what was already transferred.