Search⌘ K
AI Features

Currying and Uncurrying

Explore how to convert functions between curried and uncurried forms using Haskell's curry and uncurry functions. Learn partial application techniques for functions with multiple arguments and apply these to practical examples, enhancing your functional programming skills.

Currying functions with more arguments

The technique of currying is not limited to functions with two arguments. If we have a function with three arguments like this:

Haskell
isTriangleTuple :: (Double, Double, Double) -> Bool
isTriangleTuple (alpha, beta, gamma) = alpha + beta + gamma == 180
main = print (isTriangleTuple (90, 45, 45))

we also can turn it into its curried form:

Haskell
isTriangle :: Double -> Double -> Double -> Bool
isTriangle alpha beta gamma = alpha + beta + gamma == 180
main = print (isTriangle 90 50 50)

and we can use a partial application with one or two arguments.

mustBeSixty = isTriangle
...