Understanding the ($)
Operator in Haskell
The ($)
operator is a type of function composition in Haskell, also known as the apply operator. It is defined as follows:
($) :: (a -> b) -> a -> b
f $ a = f a
This is nearly identical to the official definition, except that the official definition uses a sophisticated type TYPE
:
($) :: forall r a (b :: TYPE r). (a -> b) -> a -> b
f $ x = f x
The TYPE
type is a type-level computation, which allows programs to be written at the type-level. It is necessary in the ($)
operator definition because it allows functions to be applied at the type-level, allowing for more efficient computation.