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

Guard Limitations in let #317

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions language/Pattern-Matching.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,36 @@ compare _ _ = EQ

(The name `otherwise` is a synonym for `true` commonly used in guards.)

Guard Limitations in `let`
----------------------------

Guards are [currently not supported](purescript/purescript#3200) with patterns other than simple identifiers in `let` expressions. For example, this does not compile:
```purs
-- This doesn't work
f1 :: Int
f1 =
let
(Tuple a b)
| false = Tuple 1 2
| otherwise = Tuple 3 4
in
a
```

A workaround is to separate the constructor pattern from the guard:
```purs
f2 :: Int
f2 =
let
t
| false = Tuple 1 2
| otherwise = Tuple 3 4

Tuple a b = t
in
a
```

Pattern Guards
--------------

Expand Down