Collection of absurdly concise Haskell code - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Vincent L

Hi,
Is there a webpage or gist or whatever listing the "best" (or worse ? depending of the pov) Haskell one liner functions that are so much concise that no ones understand them ?

Vincent L

not because of badly written code, just an instance of combining too much functions or operators

Georgi Lyubenov // googleson78

here's one I like

import Control.Applicative (ZipList(..))

transpose :: [[a]] -> [[a]]
transpose = getZipList . traverse ZipList
Joel McCracken

just take any haskell code and paste it in http://pointfree.io/

Daniel Díaz Carrete

One classic is this definition of the "powerset" function:

powerset :: [a] -> [[a]]
powerset = filterM (const [True,False])
Reed Mullanix
dup :: a -> (a,a)
dup = join (,)
TheMatten
variations :: Int -> [a] -> [[a]]
variations = replicateM
Torsten Schmits

would be nice if you could include an explanation with your examples

Georgi Lyubenov // googleson78

ah like combinatorial variations?

Pedro Minicz

Good old catamorphism:

newtype Fix f = Fix { unFix :: f (Fix f) }

cata :: Functor f => (f a -> a) -> Fix f -> a
cata alg = alg . fmap (cata alg) . unFix