Sectioning is a concise way to partially apply arguments to infix operators.
For example, if we want to write a function which adds "ing" to the end of a word we can use a section to succinctly define a function.
> (++ "ing") "laugh" "laughing"
Notice how we have partially applied the second argument. Normally, we can only partially apply the arguments in the specified order.
We can also use left sectioning to partially apply the first argument.
> ("re" ++) "do" "redo"
We could equivalently write this using normal prefix partial application:
> ((++) "re") "do" "redo"
Beginners often incorrectly section negation.
> map (-1) [1,2,3] ***error: Could not deduce...
This does not work as
-1 is parsed as the literal
-1 rather than the sectioned operator
- applied to
subtract function exists to circumvent this issue.
> map (subtract 1) [1,2,3] [0,1,2]