9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "David Leimbach" <leimy2k@gmail.com>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu>
Subject: Re: [9fans] Concurrency and message passing with Newsqueak
Date: Wed, 23 May 2007 06:32:57 -0700	[thread overview]
Message-ID: <3e1162e60705230632hb37804fra4e6773d480ccec3@mail.gmail.com> (raw)
In-Reply-To: <20070522233441.068EE5B3E@mail.bitblocks.com>

On 5/22/07, Bakul Shah <bakul+plan9@bitblocks.com> wrote:
> > > 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.
>

The channel itself has no memory of what was transferred, but I can't
think of a good reason one couldn't also memoize the remainder
computation needed such that if the spawned process/thread were to
stay alive for multiple runs, one could avoid re-computing the result,
which is what Haskell is doing, except that it's also probably caching
the results of "take" applied to "primes" in your case :-)


  reply	other threads:[~2007-05-23 13:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-18 23:45 Uriel
2007-05-19  3:24 ` Micah Stetson
2007-05-19  4:03   ` Rob Pike
2007-05-19  4:12     ` erik quanstrom
2007-05-19  4:36     ` W B Hacker
2007-05-19  4:55       ` Rob Pike
2007-05-19  5:13         ` W B Hacker
2007-05-19  6:38         ` Kris Maglione
2007-05-19 16:12           ` Russ Cox
2007-05-22 18:32       ` David Leimbach
2007-05-22 22:07         ` W B Hacker
2007-05-22 23:34         ` Bakul Shah
2007-05-23 13:32           ` David Leimbach [this message]
2007-06-01  4:59             ` Jeff Sickel
2007-06-01 11:28               ` David Leimbach
2007-06-01 13:48                 ` Russ Cox

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=3e1162e60705230632hb37804fra4e6773d480ccec3@mail.gmail.com \
    --to=leimy2k@gmail.com \
    --cc=9fans@cse.psu.edu \
    /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;
as well as URLs for NNTP newsgroup(s).