Are a way to create Curried Functions from infix Operators. This can be seen as the opposite as creating operators, using back quotes ´, from functions of two arguments. This is done by enclosing the operator, and perhaps one of its arguments, in parenthesis.
In general, if # is an operator, then expressions of the form (#), (x #), and (# y) for arguments x and y are called sections, whose meaning as functions can be formalised using lambda expressions as follows:
(#) = \x -> (\y -> x # y)
(x #) = \y -> x # y
(# y) = \x -> x # yOperator sections are:
- useful for constructing Functions in a compact way.
- necessary when stating Type of Operators.
- necessary when using Operators as arguments.
Examples
Conversion
The + operator can be converted to a curried function by
(+) 1 2
(1+) 2
(+2) 1which all give the same results as 1+2.
Constructing functions in a compact way
(1+) is the successor function \y -> 1+y
(1/) is the reciprocation function \y -> 1/y
(*2) is the doubling function \x -> x*2
(/2) is the halving function \x -> x/2Stating type of operators
(+) :: Int -> Int -> IntUsing operators as arguments
The library function sum which computes the sum of a list of integers can be
defined by using the operator + as an argument to the library function foldl in following way
sum :: [Int] -> Int
sum = foldl (+) 0