-
Notifications
You must be signed in to change notification settings - Fork 300
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
Guard Limitations in let
#317
base: master
Are you sure you want to change the base?
Conversation
From what I can tell from looking at the parser, it’s not just constructor patterns that don’t work with guards, it’s any pattern other than a simple identifier. For example, it looks to me like record and array patterns and at-patterns ( |
It's that way "because". See purescript/purescript#3200. Basically multiway-if would be more general, but there's nothing fundamentally preventing it's inclusion. |
Should we add the caveat, then open a new issue to remove it? |
language/Pattern-Matching.md
Outdated
Guards are incompatable with Constructor Patterns in `let`. For example, the following function using a `Tuple` constructor pattern will not compile: | ||
```purs | ||
-- This doesn't work | ||
f1 :: Int | ||
f1 = | ||
let | ||
(Tuple a b) | ||
| false = Tuple 1 2 | ||
| otherwise = Tuple 3 4 | ||
in | ||
a | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the capitalization is a bit odd -- we don't usually capitalize "guard" or "constructor". What about:
Guards are not supported with patterns other than simple identifiers in
let
expressions. For example, this does not compile:
I don't know about linking to purescript/purescript#3200 here, but it's at least accurate to say that this isn't supported right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than this I think it's sensible to merge this while the restriction does exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied your suggestion and also added that link. I'm a fan of linking to relevant issues in the docs.
Wondering if this should also be noted in https://github.com/purescript/documentation/blob/master/language/Differences-from-Haskell.md |
Co-authored-by: Thomas Honeyman <admin@thomashoneyman.com>
This PR hasn't been merged because it's a bit incomplete, I believe. |
No description provided.