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.
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
letexpressions. 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.
Other than this I think it's sensible to merge this while the restriction does exist.
There was a problem hiding this comment.
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.