Search code examples
haskellghci

Investigating (->) with ghci and trying to get to its roots


I am trying to use ghci to investigate type (->).

I'd love to understand why I can ask :t (+), but not :t (->):

Prelude> :t (->)
<interactive>:1:2: error: parse error on input ‘->’

Luckily, both operators allow investigation using :i, so I presume it's all because (+) is a method of class Num, whereas (->) is a data.

Diving deeper into (->):

Prelude> :i (->)
data (->) (a :: TYPE q) (b :: TYPE r)   -- Defined in ‘GHC.Prim’
infixr 0 ->
instance Applicative ((->) a) -- Defined in ‘GHC.Base’
instance Functor ((->) r) -- Defined in ‘GHC.Base’
instance Monad ((->) r) -- Defined in ‘GHC.Base’
instance Monoid b => Monoid (a -> b) -- Defined in ‘GHC.Base’
instance Semigroup b => Semigroup (a -> b) -- Defined in ‘GHC.Base’

But there is no trace of data (->) in the Hackage page for GHC.Prim. Possibly I am checking the wrong language version, but AFAIS 0.5.3 is the most recent one, and my ghci version is the latest.

Where can I find the declaration of data (->)?

Eventually, I'd like to read about TYPE, but all the pages I retrieve on Google are talking of type.

Where can I find information about TYPE?


Solution

  • Since answers have been given in the comments, I sum them up here:

    • (->) is a type constructor. You can investigate it with :k (->) @Willem van Onsem

    • GHC.Prim has no source code anywhere. It is completely generated by the compiler and you don't need to bother looking at it. When GHCi tells you something is defined there, read that as saying it comes "from the sky" @dfeuer