0
我为int类型的向量来定义一个自定义类型:GHCI:不能在自定义类型的模式匹配
data Vector = Vector Int Int Int
现在我要定义一个函数来向量添加到另一个,但不知何故,语法不正确,尽管它与Learn You a Haskell For Great Good!中使用的非常相似。
先试试,用前缀符号:
Prelude> let vp :: Vector -> Vector -> Vector
Prelude| vp (Vector a b c) (Vector d e f) = Vector (a+d) (b+e) (c+f)
<interactive>:33:1: parse error on input ‘vp’
第二个尝试,用中缀表示法:
Prelude> let vp :: Vector -> Vector -> Vector
Prelude| (Vector a b c) `vp` (Vector d e f) = Vector (a+d) (b+e) (c+f)
<interactive>:35:1: parse error on input ‘(’
我使用GHCI v7.8.4
是的,谢谢你。另一方面,如果只有GHCi像python那样引起缩进错误...... –