Reputation: 584
Why do the pattern matches overlap in this code:
(+) (Roman (_, [])) x = x
(+) x (Roman (_, [])) = x
It would make sense considering x + y
is the same as y + x
but I don't think haskell takes care of that, or does it?
Upvotes: 1
Views: 140
Reputation: 66371
The problem is that x
matches anything.
You can use at-patterns to make them unique:
(+) (Roman (_, [])) x@(Roman(_, _:_) = x
(+) x@(Roman(_, _:_) (Roman (_, [])) = x
Upvotes: 1