Skip to content

Instantly share code, notes, and snippets.

@eungju
Created April 11, 2014 11:32
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 eungju/10460521 to your computer and use it in GitHub Desktop.
Save eungju/10460521 to your computer and use it in GitHub Desktop.
Factor cleave words in Haskell
bi :: (a -> b) -> (a -> c) -> a -> (b, c)
bi f g (x) = (f x, g x)
bi2 :: (a -> b -> c) -> (a -> b -> d) -> (a, b) -> (c, d)
bi2 f g (x, y) = (f x y, g x y)
tri :: (a -> b) -> (a -> c) -> (a -> d) -> a -> (b, c, d)
tri f g h (x) = (f x, g x, h x)
tri2 :: (a -> b -> c) -> (a -> b -> d) -> (a -> b -> e) -> (a, b) -> (c, d, e)
tri2 f g h (x, y) = (f x y, g x y, h x y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment