Skip to content

Multiple Arguments

How do I give multiple arguments (i.e. inputs) to a function?

Answer

In a literal sense, functions only take a single argument. However, this argument can be a tuple.

multipleArgsFunc :: (Int, Int) -> Int
multipleArgsFunc (i,j) = i + j 

Or, the argument can be one of the inputs, and the return value can be a function which takes the next argument:

multipleArgsFunc :: Int -> (Int -> Int)
multipleArgsFunc = \i -> (\j -> (i + j))

Equivalently, but more idiomatically:

multipleArgsFunc :: Int -> (Int -> Int)
multipleArgsFunc i j = i + j

More details here

Summary

Instead of giving multiple arguments, give a single argument with multiple parts.

Comments