为什么 GHCi 不让我用种类注释我的类型?
Why isn't GHCi letting me annotate my types with kinds?
我在阅读 Haskell 论文的历史时发现了种类,并尝试 运行 the Haskell Wiki 中的一些示例。
当我这样做时,出现错误
Prelude> Int :: * [3/1792]
<interactive>:1:8: error:
Not in scope: type constructor or class ‘*’
<interactive>:1:8: error:
Illegal operator ‘*’ in type ‘*’
Use TypeOperators to allow operators in types
我不认为 'importing' TypeOperators 会有帮助,因为我认为 GHCi 认为 * 是乘法运算符,当我想让它表示一个 Kind 时。
This wiki page 似乎表明我的 GHC 版本可能尚未添加 Kinds。难道是这样吗?
我正在使用 GHCi 版本 8.0.2(来自 Ubuntu 18.04 包管理器)。
要检查 GHCi 中的种类,您可能需要使用以下内容
> :set -XKindSignatures
> :k (Int :: *)
(Int :: *) :: *
或省略 :: *
部分,让 :k
为您解决。
直接输入 Int :: *
会使 GHCi 将 Int
解释为值表达式,并寻找不存在的值构造函数 Int
。它还会将 *
解释为一种类型,而不是一种类型,这会导致错误。
我在阅读 Haskell 论文的历史时发现了种类,并尝试 运行 the Haskell Wiki 中的一些示例。
当我这样做时,出现错误
Prelude> Int :: * [3/1792]
<interactive>:1:8: error:
Not in scope: type constructor or class ‘*’
<interactive>:1:8: error:
Illegal operator ‘*’ in type ‘*’
Use TypeOperators to allow operators in types
我不认为 'importing' TypeOperators 会有帮助,因为我认为 GHCi 认为 * 是乘法运算符,当我想让它表示一个 Kind 时。
This wiki page 似乎表明我的 GHC 版本可能尚未添加 Kinds。难道是这样吗?
我正在使用 GHCi 版本 8.0.2(来自 Ubuntu 18.04 包管理器)。
要检查 GHCi 中的种类,您可能需要使用以下内容
> :set -XKindSignatures
> :k (Int :: *)
(Int :: *) :: *
或省略 :: *
部分,让 :k
为您解决。
直接输入 Int :: *
会使 GHCi 将 Int
解释为值表达式,并寻找不存在的值构造函数 Int
。它还会将 *
解释为一种类型,而不是一种类型,这会导致错误。