If a function is declared in brackets: (++) :: [a] → [a] → [a], it can be used with them without them. If they are used without parentheses, they must be displayed between the arguments: "!" ++ "?"
"!" ++ "?"
but in parentheses they look like ordinary functions: (++) "!" "?"
(++) "!" "?"
.
Haskell allows "partial application" of functions, so ("!"++)
matches (++) "!"
or \x -> (++) "!" x
\x -> (++) "!" x
, and (++"?")
same as \x -> (++) x "?"
. (A “partial application” is in quotation marks because functions in Haskell always have only one argument, so the application is no longer “partial”, and in other languages (++) it will be considered as a function of two arguments, therefore, when there is only one argument applied, the function is considered partially applied - in this sense it may be useful to view ("!" ++) as partially applied (++))
The second example is a valid way to use (/), but if you use (/) it is no longer an infix function, so you get an error trying to specify the first argument (/) before the function name: 3(/)
. It still works if you remove the brackets: (3 /)
matches ((/) 3)
or (\x -> (/) 3 x)
or (\x -> 3 / x)
source share