【发布时间】:2016-06-11 22:35:20
【问题描述】:
我试图定义一个特定类型的值,如“Int”,但 Prelude 似乎不支持它?
Prelude> let c::Int = 4
Prelude|
<interactive>:49:8:
Illegal type signature: ‘Int’
Perhaps you intended to use ScopedTypeVariables
In a pattern type-signature
Prelude> let [Int]c=4
Prelude|
<interactive>:51:5: Parse error in pattern: [Int]
如何纠正?
【问题讨论】:
-
类型签名可以出现在自己的行(在 let、where 或顶级声明中)或表达式中。类型签名不适用于绑定的左侧。
-
"如何修正?" - 错误说明如何 - “也许您打算使用 ScopedTypeVariables”。使用
:set -XScopedTypeVariables在 ghci 中启用 ScopedTypeVariables。也就是说,如果你想使用这种特定的语法。 -
我来到这里是想有人想在
let块中放置type声明。我只是去检查报告,看看你是否可以合法地这样做......你不能。 (但是,您可以在其中放置一个固定性声明......很奇怪,是吗?)