haskell / haskell/error-messages
Scoped type variables not suggested
- Dominant language
- No language data
- Stars
- 76
- Forks
- 19
- PR merge metrics
- No merged PRs in 30d
Description
Consider the following file:
```hs
module ErrMsg where
f :: a -> a
f x = y
where
y :: a
y = x
```
When loaded up in GHCi we get the following error message:
```
ErrMsg.hs:7:9: error:
• Couldn't match expected type ‘a1’ with actual type ‘a’
‘a1’ is a rigid type variable bound by
the type signature for:
y :: forall a1. a1
at ErrMsg.hs:6:5-10
‘a’ is a rigid type variable bound by
the type signature for:
f :: forall a. a -> a
at ErrMsg.hs:3:1-11
• In the expression: x
In an equation for ‘y’: y = x
In an equation for ‘f’:
f x
= y
where
y :: a
y = x
• Relevant bindings include
y :: a1 (bound at ErrMsg.hs:7:5)
x :: a (bound at ErrMsg.hs:4:3)
f :: a -> a (bound at ErrMsg.hs:4:1)
|
7 | y = x
|
```
The fact that `ScopedTypeVariables` is never even mentioned is particularly egregious, in my opinion. Also, note that the same error message is produced with `ScopedTypeVariables` enabled, and doesn't mention using an explicit `forall`.
### Suggested error message
When `ScopedTypeVariables` is **off**:
```
• Couldn't match expected type ‘a1’ with actual type ‘a’
The type variable ‘a’ is not in scope in the type signature
for ‘y’, therefore it gets renamed to ‘a1’ and is not the same
as ‘a’
Consider enabling ScopedTypeVariables and including an explicit
forall in the type signature for ‘f’ in order to bring ‘a’ into scope
• Relevant type variables include
‘a1’ (bound at ErrMsg.hs:6:5-10, in the signature for ‘y’)
‘a’ (bound at ErrMsg.hs:3:1-11, in the signature for ‘f’)
• Relevant bindings include
y :: a1 (bound at ErrMsg.hs:7:5)
x :: a (bound at ErrMsg.hs:4:3)
f :: a -> a (bound at ErrMsg.hs:4:1)
|
7 | y = x
| ^
```
When `ScopedTypeVariables` is **on** simply replace this line:
```
Consider enabling ScopedTypeVariables and including an explicit
forall in the type signature for ‘f’ in order to bring ‘a’ into scope
```
With this:
```
Consider including an explicit forall in the type signature for ‘f’
in order to bring ‘a’ into scope
```
This sort of error would also benefit greatly from having a further explanation linked. I've seen discussions of giving errors unique ids and having a collection of explanations that can be referenced. This seems like a good application for that.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.