This post and other sources like this insist that the definition of the $-operator is
($) :: (a -> b) -> a -> b
f $ x = f x
or
($) f x = f x
or
($) = id
but I didn't understand why this definition would be able to replace parentheses, so I tried to reproduce that myself and examine the behaviour, by defining:
k :: (a -> b) -> a -> b
k f x = f x
But what I got is:
-- these work:
(+2) `k` 4
(+2) `id` 4
sum `k` [1,2]
sum `id` [1,2]
map (flip(-)3) $ filter even `k` filter (>=0) [-5..10]
map (flip(-)3) $ filter even `id` filter (>=0) [-5..10]
-- these don't:
sum `k` 1:[2]
sum `id` 1:[2]
map (flip(-)3) `id` filter even $ filter (>=0) [-5..10]
Shouldn't k
be a replacement for $
? What am I doing wrong?