Haskell for Perl ProgrammersInfinite ListsPrimes (with better efficiency)

3.3. Primes (with better efficiency)

primes = sieve [2..] where
    sieve (p:xs) =
        p : (sieve (remove p xs)) where
            remove what (a:as)  | a < what = a:(remove what as)
                                | a == what = (remove (what+p) as)
                                | a > what = a:(remove (what+p) as)

Written by Shlomi Fish