What is the difference between the dot (.)
and the dollar sign ($)
?
As I understand it, they are both syntactic sugar for not needing to us
Also note that ($)
is the identity function specialised to function types. The identity function looks like this:
id :: a -> a
id x = x
While ($)
looks like this:
($) :: (a -> b) -> (a -> b)
($) = id
Note that I've intentionally added extra parentheses in the type signature.
Uses of ($)
can usually be eliminated by adding parenthesis (unless the operator is used in a section). E.g.: f $ g x
becomes f (g x)
.
Uses of (.)
are often slightly harder to replace; they usually need a lambda or the introduction of an explicit function parameter. For example:
f = g . h
becomes
f x = (g . h) x
becomes
f x = g (h x)
Hope this helps!