Skip to content

Instantly share code, notes, and snippets.

@betaveros
Last active December 17, 2015 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betaveros/5648537 to your computer and use it in GitHub Desktop.
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.
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