Skip to content

Instantly share code, notes, and snippets.

@monadplus
Created July 2, 2022 06:44
Show Gist options
  • Save monadplus/3eb530a9972c79dbbe6cbc9f2aaed7b0 to your computer and use it in GitHub Desktop.
Save monadplus/3eb530a9972c79dbbe6cbc9f2aaed7b0 to your computer and use it in GitHub Desktop.
Point-Free or Die: Tacit Programming in Haskell and Beyond
{- Point-Free or Die: Tacit Programming in Haskell and Beyond
https://www.youtube.com/watch?v=seVSlKazsNk
g . f = (.) g f x
= \x -> g (f x)
= \x -> g $ f x
= \x -> g . f $ x
= g . f
aggregate f = sum . map f
aggregate f = (.) sum (map f)
aggregate f = (.) sum $ map f
aggregate f = (.) sum . map $ f
aggregate = \f -> (.) sum . map $ f
aggregate = (.) sum . map
aggregate = (sum .) . map
(sum .) . map
\f g -> (f .) . g
-- Eta abstraction
\f g -> (f .) . g
\f g x -> (f .) . g $ x
\f g x -> (f .) $ g x
\f g x -> (f .) (g x)
\f g x -> f . (g x)
\f g x y -> f $ (g x) y
\f g x y -> f (g x y)
-- New combinator: blackbird
f ... g = (f .) . g
- \x y -> f (g x y)
-- Mastermind game
exactMatches = length . filter id ... zipWith (==)
colorMatches ps qs = sum $ zipWith min (countColors ps) (countColors qs)
colorMatches ps qs = sum $ (zipWith min `on` countColors) ps qs
colorMatches = sum ... zipWith min `on` countColors
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment