[Haskell-cafe] Re: Another optimization question

Luke Palmer lrpalmer at gmail.com
Sun May 18 11:11:13 EDT 2008


On Sat, May 17, 2008 at 11:45 PM, Jeroen <yrn001 at gmail.com> wrote:
> I only tested with -O2 and my primes implementation
> is the Sieve of Eratosthenes and has signature
>
> primes :: Integral a => [a]

I'm guessing that you already know this, but this declares that primes
should *not* be cached globally (and is the reason for the
monomorphism restriction).  Depending on how it is used, it means that
you might be computing the list of primes many times.  Using a
monomorphic signature like [Int] or [Integer] will allow primes to be
cached, probably increasing the performance quite dramatically.

Luke


More information about the Haskell-Cafe mailing list