【发布时间】:2018-11-29 03:25:06
【问题描述】:
我们知道1:2:[] 将返回[1,2]。
我刚试过1:2,这给了我一个错误。
<interactive>:48:1: error:
? Non type-variable argument in the constraint: Num [a]
(Use FlexibleContexts to permit this)
? When checking the inferred type
it :: forall a. (Num a, Num [a]) => [a]
我知道这可能不是一个合适的例子,因为: 操作包含一个元素和一个列表。但我只是想知道它在1:2:[] 中是如何工作的
【问题讨论】:
-
(:)必须是右关联的,因为如果1:2:[]被解析为(1:2):[]会产生类型错误。
标签: haskell operator-precedence syntactic-sugar cons