As another example, we have the function map
, which takes a function and a list of values, and applies the function to each value of the list:
map :: (a -> b) -> [a] -> [b]
Let's say we want to increment each value in a list. You may decide to define your own function, which adds one to its argument, and map
that function over your list
addOne x = plus 1 x
map addOne [1,2,3]
but if you have another look at addOne
's definition, with parentheses added for emphasis:
(addOne) x = ((plus) 1) x
The function addOne
, when applied to any value x
, is the same as the partially applied function plus 1
applied to x
. This means the functions addOne
and plus 1
are identical, and we can avoid defining a new function by just replacing addOne
with plus 1
, remembering to use parentheses to isolate plus 1
as a subexpression:
map (plus 1) [1,2,3]