[Haskell-cafe] Re: Looking for the fastest Haskell primes algorithm

Heinrich Apfelmus apfelmus at quantentunnel.de
Thu Apr 16 03:58:43 EDT 2009

Niemeijer, R.A. wrote:
> Today I happened to need a large list of prime numbers.
> Obviously this is a well-known problem, so I figured there would
> be something on Hackage that I could use. Surprisingly, there isn't,
> or if there is it's not easy to find.
> Since it's such a common problem I'd say it would be a good idea to
> add a package to Hackage that exports
> primes :: [Integer]
> and hides the ugly implementation details.

+1 except that exporting the potentially infinite list of primes is
problematic in that it may become a memory leak.

I'd suggest to export two versions

  primes  :: [Integer]
  primes' :: () -> [Integer]

for casual (i.e. throwaway program to solve a Project Euler problem) and
for memory aware use respectively.



More information about the Haskell-Cafe mailing list