Skip to content

Multiple Arguments

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


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


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