This is the code I have:
connected :: [(Integer,Integer)] -> Bool
connected [] = True
connected [(_,_)] = True
connected (a,b):(c,d):xs
| a > c = False
|otherwise = connected (c,d):xs
When I load it GHCi it shows
error: parse error in pattern: connected
Where did I make a mistake?
You need to add parentheses around your cons expressions in two places:
Function application binds more tightly than infix operators, so
connected (c,d) : xs
gets parsed as(connected (c,d)) : xs
.A similar thing happens in the pattern expression. Although the unhelpful error message you get there is rather unfortunate.
Opinionated side note: I recommend always writing infix operators with spaces around them (for example,
a : b
instead ofa:b
), because I think omitting the whitespace subtly implies that the operator binds more tightly than it really does.