[Haskell-beginners] Efficient sieve of erastothenes, for solving project euler problem #10?

Malcolm Reynolds malcolm.reynolds at gmail.com
Sun Nov 23 17:28:23 EST 2008

Hello all,

I'm attempting to learn Haskell by going through the project euler
problems. Number 10,
http://projecteuler.net/index.php?section=problems&id=10 , involves
summing prime numbers. It's easy in terms of coding something up that
works, but I'm having a lot of trouble getting decent performance.
I've learned a reasonable amount of ML at uni but Haskell is the first
lazy language I've used.. I think the inefficiency is possibly due to
the laziness but I'm not positive.

I'd love if someone could show me how to do this in Haskell somewhere
near as fast as C - at the moment I have a C version which runs in
about a tenth of a second (
). My haskell attempts are
(using the sieve) and
(using possibly an even worse method, but seems to be a bit faster).

If anyone could point out any neat strictness annotations or anything
else I could put in, that would be cool.



More information about the Beginners mailing list