Corecursive, infinite primes list

Haskell

New/Simple BSD

A pair of functions which use each other to produce an infinite list of prime numbers

Download (right click, save as, rename as appropriate)

Embed

1
2
3
4
5
6
primes :: [Integer]
primes = 2:L.filter isPrime [3,5..]

isPrime :: Integer -> Bool
isPrime x = go primes
    where go (n:ns) = if n*n > x then True else x `rem` n /= 0 && go ns