From ff352cdedb786325d3f7e5a7fa41f8b3b5cdbcd9 Mon Sep 17 00:00:00 2001 From: Miles Frain Date: Sun, 17 May 2020 12:17:23 -0600 Subject: [PATCH 1/3] Guard Limitations in `let` --- language/Pattern-Matching.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/language/Pattern-Matching.md b/language/Pattern-Matching.md index 5c15abea..9e8a4e01 100644 --- a/language/Pattern-Matching.md +++ b/language/Pattern-Matching.md @@ -176,6 +176,36 @@ compare _ _ = EQ (The name `otherwise` is a synonym for `true` commonly used in guards.) +Guard Limitations in `let` +---------------------------- + +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 +``` + +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 -------------- From 80668a5385b2be728e56d68f7bd38ccf64c17eb2 Mon Sep 17 00:00:00 2001 From: milesfrain Date: Fri, 21 Aug 2020 20:07:14 -0700 Subject: [PATCH 2/3] Apply review feedback --- language/Pattern-Matching.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/language/Pattern-Matching.md b/language/Pattern-Matching.md index 9e8a4e01..eda156c1 100644 --- a/language/Pattern-Matching.md +++ b/language/Pattern-Matching.md @@ -179,7 +179,7 @@ compare _ _ = EQ Guard Limitations in `let` ---------------------------- -Guards are incompatable with Constructor Patterns in `let`. For example, the following function using a `Tuple` constructor pattern will not compile: +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 From 028f93a7d9fc24b1d71a51b53f477fbc015495d4 Mon Sep 17 00:00:00 2001 From: milesfrain Date: Sun, 23 Aug 2020 14:58:14 -0700 Subject: [PATCH 3/3] lowercase guard Co-authored-by: Thomas Honeyman --- language/Pattern-Matching.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/language/Pattern-Matching.md b/language/Pattern-Matching.md index eda156c1..0e490c4a 100644 --- a/language/Pattern-Matching.md +++ b/language/Pattern-Matching.md @@ -192,7 +192,7 @@ f1 = a ``` -A workaround is to separate the constructor pattern from the Guard: +A workaround is to separate the constructor pattern from the guard: ```purs f2 :: Int f2 =