haskell / haskell/error-messages

Escaping skolems (e.g. with `runST`) are not mentioned in GHC >= 9.2

Open
#544 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
76
Forks
19
PR merge metrics
No merged PRs in 30d

Description

In GHC 9.0 and below, the following code would produce an error message that mentions the phrase `type variable 's' would escape its scope`.

```hs
runST (newSTRef 5)
```

```
:3:8: error:
• Couldn't match type ‘a’ with ‘STRef s Integer’
Expected: ST s a
Actual: ST s (STRef s Integer)
because type variable ‘s’ would escape its scope
This (rigid, skolem) type variable is bound by
a type expected by the context:
forall s. ST s a
at :3:7-18
• In the first argument of ‘runST’, namely ‘(newSTRef 5)’
In the expression: runST (newSTRef 5)
In an equation for ‘it’: it = runST (newSTRef 5)
• Relevant bindings include it :: a (bound at :3:1)
```

GHC >= 9.2 only reports the type mismatch and doesn't mention anything about escaping scopes anymore.

```
:3:8: error: [GHC-25897]
• Couldn't match type ‘a’ with ‘STRef s Integer’
Expected: ST s a
Actual: ST s (STRef s Integer)
‘a’ is a rigid type variable bound by
the inferred type of it :: a
at :3:1-18
• In the first argument of ‘runST’, namely ‘(newSTRef 5)’
In the expression: runST (newSTRef 5)
In an equation for ‘it’: it = runST (newSTRef 5)
• Relevant bindings include it :: a (bound at :3:1)
```

That `s` would escape its scope is arguably the most important part of the error message, so if this is reverted, that line should probably be moved before the type mismatch. Especially in cases like this with `runST`, the type mismatch is not very meaningful without that piece of information.

For example:
```
:3:8: error: [GHC-25897]
• The rigid type variable 's' would escape its scope
• Couldn't match type ‘a’ with ‘STRef s Integer’
Expected: ST s a
Actual: ST s (STRef s Integer)
‘a’ is a rigid type variable bound by
the inferred type of it :: a
at :3:1-18
• In the first argument of ‘runST’, namely ‘(newSTRef 5)’
In the expression: runST (newSTRef 5)
In an equation for ‘it’: it = runST (newSTRef 5)
• Relevant bindings include it :: a (bound at :3:1)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.