研究ghci(->)并尝试扎根 [英] Investigating (->) with ghci and trying to get to its roots

查看:74
本文介绍了研究ghci(->)并尝试扎根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ghci调查类型(->).

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

我很想理解为什么我可以问:t (+)而不是:t (->):

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

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

幸运的是,两个运算符都允许使用:i进行调查,所以我想都是因为(+)是Num类的方法,而(->)是数据.

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

深入研究(->):

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’

但是.可能我检查的语言版本错误,但是AFAIS 0.5.3是最新的版本,而我的ghci版本是最新的版本.

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.

在哪里可以找到data (->)的声明?

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

最终,我想阅读有关TYPE的信息,但是我在Google上检索到的所有页面都在谈论type.

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

我在哪里可以找到有关TYPE的信息?

Where can I find information about TYPE?

推荐答案

由于注释中给出了答案,因此我在这里总结一下:

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在任何地方都没有源代码.它完全由编译器生成,您无需费心查看它.当GHCi告诉您在此处定义了某些内容时,请说它是来自天空"的 @dfeuer

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

这篇关于研究ghci(-&gt;)并尝试扎根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆