User:WillNess
Jump to navigation
Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
I am a newbie, interested in Haskell.
I like this:
primes = 2 : g (fix g) -- double staged production idea due to M. O'Neill
where
g xs = 3 : (gaps 5 $ foldi (\(q:qs) -> (q:) . union qs)
[[p*p, p*p+2*p..] | p <- xs])
gaps k s@(x:xs)
| k < x = k : gaps (k+2) s -- | k<=x = minus [k,k+2..] xs
| True = gaps (k+2) xs -- inlined to avoid a space leak
fix g = xs where xs = g xs -- global defn to avoid space leak
foldi
is on Tree-like folds. More at Prime numbers.