【发布时间】:2018-02-14 11:09:32
【问题描述】:
这是我的代码:
connected :: [(Integer,Integer)] -> Bool
connected [] = True
connected [(_,_)] = True
connected (a,b):(c,d):xs
| a > c = False
|otherwise = connected (c,d):xs
当我加载 GHCi 时,它会显示
error: parse error in pattern: connected
我在哪里做错了?
【问题讨论】:
-
次要风格注释:
foo | x = False | otherwise = something是(IMO)更常见的写作foo = not x && something。在您的情况下,您可以使用connected (...) = a <= c && connected (...)。
标签: haskell pattern-matching operator-precedence parse-error