Haskell's ($) is a magic operator?

前端 未结 1 1192
北恋
北恋 2020-12-24 05:01

Say I have the following functions:

infixr 0 <|

{-# INLINE (<|) #-}
(<|) :: (a -> b) -> a -> b
f <| x = f x

foo :: a -> (forall b.          


        
相关标签:
1条回答
  • 2020-12-24 05:22

    Yes, there's a small amount of compiler magic around ($) to handle impredicative types. It was introduced because everyone expects

    runST $ do
      foo
      bar
      baz
    

    to typecheck, but it cannot normally. For more details see here (search runST), this email, and this email. The short of it is that there's actually a special rule in the type-checker specifically for ($) which gives it the ability to resolve the common case of impredicative types.

    0 讨论(0)
提交回复
热议问题