Last active
December 17, 2015 17:49
-
-
Save betaveros/5648537 to your computer and use it in GitHub Desktop.
An "efficient" prime generator with the Sieve of Eratosthenes in Haskell, as close to point-free (= unreadable) as I could make it.
This file contains 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
import Control.Applicative (liftA2, liftA3) | |
import qualified Data.Map as M (empty, lookup, insertWith, delete) | |
import Data.Function (fix) | |
import Control.Monad (join) | |
primes = fix (flip (flip liftA2 head) tail . (liftA2 (liftA3 liftA2 (flip flip | |
. M.lookup)) (liftA2 ($) ((.) . (.) (liftA3 maybe) . (.) . (:)) . ((. flip | |
(.) . liftA2 (M.insertWith (++)) (join (*)) (replicate 1)) . flip (.))) | |
(((. flip (.) . liftA2 (.) (foldl . ((. flip flip) . flip flip (replicate | |
1) . flip liftA2 . (.) (M.insertWith (++)) . (+))) M.delete) . (flip (.)) | |
. (.) (.) ) ))) [2..] M.empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment