这是我拥有的代码:
connected :: [(Integer,Integer)] -> Bool
connected [] = True
connected [(_,_)] = True
connected (a,b):(c,d):xs
| a > c = False
|otherwise = connected (c,d):xs
当我在GHCi中加载它时,它显示如下错误:
我犯了什么错误?
错误:模式匹配中的语法错误:connected
foo | x = False | otherwise = something
更常见的写法是foo = not x && something
。在你的情况下,你可以使用connected (...) = a <= c && connected (...)
。 - chi