Hi, I am writing here because I do not understand a current limitation of ($)
that nobody else could explain to me: It is not fully representation polymorphic. I.e. its type is:
($) :: forall (r :: GHC.Types.RuntimeRep) a (b :: TYPE r). (a -> b) -> a -> b
The limitation is explained in the levity polymorphism section of the manual here. However, this explanation is indeed unsatisfying because this seems to be merely an implementation detail:
{-# INLINE ($) #-}
($) :: forall r a (b :: TYPE r). (a -> b) -> a -> b
f $ x = f x
There is no reasoning on why ($)
is not simply eta reduced; Indeed: defining it as:
($) :: forall repa repb (a :: TYPE repa) (b :: TYPE repb). (a -> b) -> a -> b
($) f = f -- or even ($) = id
{-# INLINE ($) #-}
infixr 0 $
seems to work perfectly fine. Now the questions are: Am I overlooking something? Are there any problems with that implementation?
See here for a showcase of this implementation being useful in cases where the original $
is not polymorphic enough.