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

有些话、适合烂在心里 提交于 2019-12-23 09:12:33

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/57903080/investigating-with-ghci-and-trying-to-get-to-its-roots

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!