Skip to content

Instantly share code, notes, and snippets.

@amar47shah
Created July 23, 2015 13:17
Show Gist options
  • Save amar47shah/3b9b87400742e97eba80 to your computer and use it in GitHub Desktop.
Save amar47shah/3b9b87400742e97eba80 to your computer and use it in GitHub Desktop.
-- Derivation of (f .) . g == f (g x y)
-- Examples
countWhere = (length .) . filter
duplicate = (concat .) . replicate
concatMap = (concat .) . map
-- Could also be written
countWhere p xs = length (filter p xs)
duplicate n xs = concat (replicate n xs)
concatMap f xs = concat (map f xs)
-- Reverse derivation
-- (f .) . g
-- == \x -> ((f .) . g) x
-- == \x -> (f .) (g x)
-- == \x -> f . (g x)
-- == \x y -> (f . (g x)) y
-- == \x y -> f ((g x) y)
-- == \x y -> f (g x y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment