4

I'm not familiar with GHC internals but I have a couple questions about ConstraintKinds.

It says from GHC.Exts that

data Constraint :: BOX

which is misleading because Constraint is a kind of sort BOX. This brings us to the first question: we can import and export kinds? How does that work?

Please correct me on this next part if I'm totally off. From trying out different imports and glancing around at the source on hackage, my guess is that GHC.Exts imports Constraint from GHC.Base, who in turn, imports it from GHC.Prim. But I do not see where it is defined in GHC.Prim?

4

1 回答 1

7

Constraint据我所知,在任何 Haskell 源文件中都没有定义。它是一个内置的有线名称,被定义为属于GHC.PrimGHC 源本身。所以特别Constraint是不是一个提升的数据类型,没有相应的数据类型*被称为Constraint.

GHC 中还有其他种类的处理方式类似,例如AnyKOpenKind甚至BOX其本身。

GHC 在数据类型和种类以及上述任何内容之间并没有真正在内部产生很大差异。这就是为什么它们都显示为使用定义,data尽管具有不同的目标类型。

请注意,就 GHC 而言,我们也有

data BOX :: BOX

但是,用户不可能直接定义 super-kind 的新“种类” BOX

据我所知,导入/导出在类型和种类命名空间之间也没有区别。所以例如

import GHC.Exts (OpenKind, BOX, Constraint)

是合法的。事实上,如果你接着说

x :: Constraint
x = undefined

你没有得到范围错误,而是一个种类错误,说需要一种类型*,但提供了一种类型/种类BOX

我也许还应该说,关于种类的整个故事有些变化,并且正在讨论的提案可以稍微改变这一点:有关相关讨论,请参见例如https://ghc.haskell.org/trac/ghc/wiki/NoSubKinds .

于 2015-04-10T15:32:35.407 回答