diff --git a/language/Pattern-Matching.md b/language/Pattern-Matching.md index 5c15abea..0e490c4a 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 [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 --------------