*(星)或其他类型在haddock的实例列表中表示什么 [英] What does * (star) or other kinds mean in an instance list of haddock

查看:148
本文介绍了*(星)或其他类型在haddock的实例列表中表示什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览各种软件包的haddocks我经常会看到像这样的实例文​​档(

 类别k(强制k)
类别*( - >)

或此( Control.Monad.Trans.Identity ):

  MonadTrans(IdentityT *)



这种签名究竟意味着什么?它不会显示在源代码中,但我已经注意到它似乎发生在使用 PolyKinds 扩展名的模块中。我怀疑它可能像一个TypeApplication,但有一种。所以,例如最后一个例子表示如果它的第一个参数是 *

$ b,那么 IdentityT 是一个monad转换器。
$ b

所以我的问题是:


  • 我的解释是否正确,类签名是指什么?

  • 在第一个 Category 实例中,我该如何知道 k 是一种而不是一种类型?或者我只需要知道类别

  • 这个语法的源代码类型是什么?



我不是要求解释种类。

解决方案

引用理查德·艾森伯格最近发布的关于haskell-咖啡馆邮件列表


Haddock有时会使用 -XPolyKinds 启用。问题在于GHC通常不需要编写好的参数,也不会将它们打印出来(除非你说 -fprint-explicit-kinds )。但是,我相信,当 -XPolyKinds 开启时,Haddock会打印出种类。所以这两个不同的定义实际上是相同的:它只是一个模块具有 -XPolyKinds 而另一个不是。



* 是普通类型的类型。所以 Int 有种 * (我们写 Int :: * ),而也许有种 * - > * Typeable 实际上有类型 forall k。 k - >约束,这意味着它是polykinded。在下面的第一个片段中, Typeable * 参数实例化 k * ,因为类型变量a有类型 *




所以是的,正如你猜测的那样,它与 PolyKinds 有关。 Haddock用一种显式的应用来呈现这些poly-kinded类型。恰巧, Category 是poly-kinded,类型 forall k。 (k - > k - > *) - >约束,所以Haddock会在每个实例旁边呈现出类似的应用程序。



在我看来,这是Haddock的错误或错误特征,据我所知,没有等效的源代码模拟。这是令人困惑的,我不知道有更好的方式来理解它,而不是认识它通常表现出来的方式,并从上下文中直观地推断出发生了什么。


Browsing the haddocks of various packages I often come along instance documentations that look like this (Control.Category):

Category k (Coercion k)
Category * (->)

or this (Control.Monad.Trans.Identity):

MonadTrans (IdentityT *)

What exactly here does the kind signature mean? It doesn't show up in the source, but I have already noticed that it seems to occur in modules that use the PolyKinds extension. I suspect it is probably like a TypeApplication but with a kind. So that e.g. the last example means that IdentityT is a monad transformer if it's first argument has kind *.

So my questions are:

  • Is my interpretation correct and what exactly does the kind signature refer to?
  • In the first Category instance, how am I supposed to know that k is a kind and not a type? Or do I just have to know the arity of Category?
  • What is the source code analog to this syntax?

I am not asking for an explanation of kinds.

解决方案

To quote Richard Eisenberg’s recent post on the haskell-cafe mailing list:

Haddock struggles sometimes to render types with -XPolyKinds enabled. The problem is that GHC generally does not require kind arguments to be written and it does not print them out (unless you say -fprint-explicit-kinds). But Haddock, I believe, prints out kinds whenever -XPolyKinds is on. So the two different definitions are really the same: it's just that one module has -XPolyKinds and the other doesn't.

The * is the kind of ordinary types. So Int has kind * (we write Int :: *) while Maybe has kind * -> *. Typeable actually has kind forall k. k -> Constraint, meaning that it's polykinded. In the first snippet below, the * argument to Typeable instantiates k with *, because type variable a has kind *.

So yes, as you guessed, it has to do with PolyKinds. Haddock renders these poly-kinded types with a sort of "explicit kind application". It just so happens that Category is poly-kinded, having the kind forall k. (k -> k -> *) -> Constraint, so Haddock renders the kind application alongside each instance.

In my opinion, this is a bug or misfeature of Haddock, since there is no equivalent source code analog as far as I know. It is confusing, and I don’t know of a better way to understand it than to recognize the way it usually manifests and visually infer what’s going on from the context.

这篇关于*(星)或其他类型在haddock的实例列表中表示什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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