Looking at types is the best way in Haskell to get the first idea what any function does:
curry :: ((a, b) -> c) -> a -> b -> c uncurry :: (a -> b -> c) -> (a, b) -> c
curry : pair function -> curried function (it curries function).
uncurry : curried function -> pair function.
The currying Haskell Wiki page contains small exercises at the end of the page:
- Simplify
curry id - Simplify
uncurry const - Express
snd with curry or uncurry and other core Prelude functions and without lambdas - Write function
\(x,y) -> (y,x) without lambda and only with Prelude functions
Try to solve these exercises right now, they will give you an extensive idea of ββthe system and functionality of an application like Haskell.
There are some interesting uncurry applications, try passing the various arguments to the functions below and see what they do:
uncurry (.) :: (b -> c, a -> b) -> a -> c uncurry (flip .) :: (b -> a -> b1 -> c, b) -> b1 -> a -> c uncurry (flip (.)) :: (a -> b, b -> c) -> a -> c uncurry ($) :: (b -> c, b) -> c uncurry (flip ($)) :: (a, a -> c) -> c -- uncurry (,) is an identity function for pairs uncurry (,) :: (a, b) -> (a, b) uncurry (,) (1,2) -- returns (1,2) uncurry uncurry :: (a -> b -> c, (a, b)) -> c uncurry uncurry ((+), (2, 3)) -- returns 5 -- curry . uncurry and uncurry . curry are identity functions curry . uncurry :: (a -> b -> c) -> (a -> b -> c) (curry . uncurry) (+) 2 3 -- returns 5 uncurry . curry :: ((a, b) -> c) -> ((a, b) -> c) (uncurry . curry) fst (2,3) -- returns 2 -- pair -> triple uncurry (,,) :: (a, b) -> c -> (a, b, c) uncurry (,,) (1,2) 3 -- returns (1,2,3)