Created
April 7, 2016 13:42
-
-
Save kcsongor/63e5a1d46394400efb06bf8cd5452e5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Data.Functor.Foldable | |
import Data.Maybe | |
g :: (Ord a, Num a) => (a, [[a]]) -> Prim [Maybe a] (a, [[a]]) | |
g (n, xs) | |
| n `elem` concatMap (take 1) xs' | |
= Cons Nothing (n + 2, xs') | |
| otherwise | |
= Cons (Just n) (n + 2, iterate (+ (2 * n)) (n * n) : xs') | |
where xs' = map (dropWhile (< n)) xs | |
primes :: [Int] | |
primes = 2 : catMaybes (ana g (3, [])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment