Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Innf107 opened this issue Apr 30, 2023 · 0 comments
Open

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

Innf107 opened this issue Apr 30, 2023 · 0 comments

Comments

@Innf107
Copy link

Innf107 commented Apr 30, 2023

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.

runST (newSTRef 5)
<interactive>: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 <interactive>: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 <interactive>:3:1)

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

<interactive>: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 <interactive>: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 <interactive>: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:

<interactive>: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 <interactive>: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 <interactive>:3:1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant