haskell / haskell/error-messages
(rigid, skolem) type variables escaping scope
- Dominant language
- No language data
- Stars
- 76
- Forks
- 19
- PR merge metrics
- No merged PRs in 30d
Description
This is an example of technical jargon in error messages which doesn't mean much to anyone but the most experienced Haskellers. Here is a simple example to reproduce this error:
```haskell
module Foo where
h :: (b -> ()) -> Int
h = error "urk"
f = h (\x -> let g :: a -> Int
g y = length [x, y]
in ())
```
The issue here is that `x` and `y` must have the same type because they are both elements of the same list, and `y` has type `a` which is bound in the type signature of `g`, but `g` is bound inside the lambda that binds the variable `x`, so the information about `a` would have to travel from inside the lambda to the outside, which is not allowed.
The error message that is produced with GHC 9.0.2 is:
```
Foo.hs:7:35: error:
• Couldn't match expected type ‘b0’ with actual type ‘a’
because type variable ‘a’ would escape its scope
This (rigid, skolem) type variable is bound by
the type signature for:
g :: forall a. a -> Int
at Foo.hs:6:18-30
• In the expression: y
In the first argument of ‘length’, namely ‘[x, y]’
In the expression: length [x, y]
• Relevant bindings include
y :: a (bound at Foo.hs:7:20)
g :: a -> Int (bound at Foo.hs:7:18)
x :: b0 (bound at Foo.hs:6:9)
|
7 | g y = length [x, y]
| ^
```
In my opinion there are a few strange things in this error message.
1. The message mentions type variables escaping a "scope", but I have not enabled `ScopedTypeVariables` so which scope does the message mean?
2. Rigid and skolem are very technical terms, could that simply be left out without upsetting advanced Haskell users?
3. The signature for `g` is written as `g :: forall a. a -> Int`, but that is not legal syntax because I haven't enabled `ExplicitForAll`.
4. Where does the variable `b0` come from? Now it is relatively clear because there is only one `b` type variable in the whole program, but what about more complicated programs?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.