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

Unbound variable in a pattern synonym #531

Open
monoidal opened this issue Oct 18, 2022 · 1 comment
Open

Unbound variable in a pattern synonym #531

monoidal opened this issue Oct 18, 2022 · 1 comment

Comments

@monoidal
Copy link
Member

This

{-# LANGUAGE PatternSynonyms #-}
pattern P x = ()

gives

M.hs:2:11: error: Not in scope: ‘x’
  |
2 | pattern P x = ()
  |           ^

I think this is too terse and the error should give more explanation. For a newcomer, it's very natural to expect it to work, because f x = () works.

For comparison,

pattern Q = x

gives

M.hs:2:13: error:
    Invalid right-hand side of bidirectional pattern synonym ‘Q’:
      ‘x’ is not bound by the LHS of the pattern synonym
    RHS pattern: x
  |
2 | pattern Q = x
  |             ^

This is better, though it could also suggest adding 'x' to the LHS, or changing it to a wildcard, or making the pattern synonym unidirectional.

@goldfirere
Copy link
Collaborator

I'm personally happy enough with the second message, but I agree the first could have a

NB: Variables in a pattern synonym are bound to the right of the '='

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

2 participants