haskell - 如何正确访问 `Constraint` 类型?

标签 haskell functional-programming constraints ghci type-kinds

我正在玩弄 ConstraintKinds在 GHCi 中。在链接的帖子中,我找到了一个很好的例子:

type NoConstraint = (() :: Constraint)

但我无法让它工作。 GHCi 自由输出 Constraint 种类,不允许我同时使用它。 IE。这是我的完整 GHCi session(我不太确定我知道正确的词;如果有一个合适的术语,我将感谢读者的编辑):

GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
Prelude> :set -XConstraintKinds -XKindSignatures
Prelude> type NoConstraint = (() :: Constraint)

<interactive>:2:28: error:
    Not in scope: type constructor or class `Constraint'
    Perhaps you meant `NoConstraint' (line 2)

如何正确访问 Constraint 类型?

最佳答案

docs 中所述, Constraint 类型需要从 Data.Kind 模块导入。请参阅下面我的 GHCi session :

Prelude> :set -XConstraintKinds -XKindSignatures
Prelude> type NoConstraint = (() :: Constraint)

<interactive>:2:28: error:
    Not in scope: type constructor or class `Constraint'
    Perhaps you meant `NoConstraint' (line 2)
Prelude> :m +Data.Kind
Prelude Data.Kind> type NoConstraint = (() :: Constraint)
Prelude Data.Kind>

关于haskell - 如何正确访问 `Constraint` 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67152967/

相关文章:

MySQL 与 Windows 上的 Haskell

haskell 检查平衡树

sql - 如何在 PostgreSQL 中使用条件查询和子查询创建唯一索引?

swift - 在 Swift 中优雅地检查两个结构体实例是否不同

sql - Mysql中的异或约束

generics - 有什么方法可以对泛型类型施加复杂的条件和约束吗?

haskell - Haskell 函数签名中 () 是什么意思?

haskell - 消失的应用程序?

javascript - 如何在 Javascript 中实现 Haskell 的 FRP Behavior 类型?

list - 返回 OCaml 中列表的第 n 个元素?