F. Zer
F. Zer

Reputation: 1279

Understanding the type of ($) operator

The module GHC/Base.hs contains the following operator definition:

($) :: forall r a (b :: TYPE r). (a -> b) -> a -> b
f $ x =  f x

Upvotes: 9

Views: 206

Answers (1)

chepner
chepner

Reputation: 531948

TYPE provides support for representation polymorphism.

The types you are used to have kind Type (formerly known as *). But there are other kinds[*] of types. Type is just an alias for TYPE LiftedRep. We could more formally write the "usual" type for ($) as

($) :: forall (a :: Type) (b :: Type) . (a -> b) -> a -> b
-- ($) :: forall (a :: TYPE LiftedRep) (b :: TYPE LiftedRep) . (a -> b) -> a -> b

The introduction of r just means that we aren't restricting b to "ordinary" types. b doesn't have to have kind TYPE LiftedRep; it can have kind TYPE r for any r that is a valid argument to TYPE.


[*] "kind" in the English sense, not the formal concept called "kind" in Haskell's type system.

Upvotes: 8

Related Questions