Elm Language Functions and Partial Application Overview


Example

Function application syntax in Elm does not use parenthesis or commas, and is instead whitespace-sensitive.

To define a function, specify its name multiplyByTwo and arguments x, any operations after equal sign = is what returned from a function.

multiplyByTwo x =
    x * 2

To call a function, specify its name and arguments:

multiplyByTwo 2  -- 4

Note that syntax like multiplyByTwo(2) is not necessary (even though the compiler doesn't complain). The parentheses only serve to resolve precedence:

> multiplyByTwo multiplyByTwo 2
-- error, thinks it's getting two arguments, but it only needs one

> multiplyByTwo (multiplyByTwo 2)
4 : number

> multiplyByTwo 2 + 2
6 : number
-- same as (multiplyByTwo 2) + 2

> multiplyByTwo (2 + 2)
8 : number