In an attempt to become less rusty, I was looking at some of the Euler challenge problems. #10 has me scratching my head. The problem statement is pretty simple: sum the primes < 2,000,000. A trivial (imperative, array-based) sieve in (your (other) language of choice) calculates this in no time flat.
The reason I _know_ that the imperative sieve runs so quickly is because I had plenty of time to write one whilst I was waiting for the Haskell one to run to conclusion; which, incidentally, it never did. Admittedly I used the "my first Haskell program" approach for sieving out primes, which runs candidate integers through an ever-increasing cascade of filters, one per prime:
> primes [] = []
> primes (n:ns) = n : primes [ n' | n' <- ns, n' `mod` n /= 0 ]
It's a neat expression of primality and showcases Haskell's lazy approach; but I'm hunting around for better (by which I mean, faster) ways to do this: ideally with derivations that are amenable to study. The Haskell wiki has some pointers (see? I _do_ google first) but if anyone with more Haskell chops fancies spending five minutes running through alternatives (especially in this case, where the upper bound is known well in advance, so a fixed array is a plausible approach) at the next meeting I'd be really appreciative.
Cheers,
jan