haskell / haskell/error-messages
Error about wrong missing instance
- Dominant language
- No language data
- Stars
- 76
- Forks
- 19
- PR merge metrics
- No merged PRs in 30d
Description
Here's a puzzling one. I've made a mistake in the second clause of `leftSkewed`. The second argument should be `Leaf n`, not `n`. Therefore I really want the error "No instance for `Num Tree`", pointing to that mistake. Instead I get the error "No instance for `Eq Tree`" pointing to the `0` match in the first clause!
I think what has happened here is that the type checker has deduced that `n :: Tree`, and given that we're passing `n - 1` to `leftSkewed` the argument to `leftSkewed` must be `:: Tree`. Then the `0` pattern requires an `Eq Tree` constraint. But I wish it would just bail out earlier and say that it can't find a `Num` instance for `Tree`!
```haskell
data Tree = Branch Tree Tree | Leaf Int
leftSkewed 0 = Leaf 0
leftSkewed n = Branch (leftSkewed (n - 1)) n
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.