From 71b702e9bd77f084dee1230433d07d8c511bbd24 Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Sun, 17 Jun 2018 18:37:13 -0400 Subject: [PATCH] Make note of #340 in the README Partial pattern matches in `do`-notation are difficult to single because they desugar down to `case` expressions with overlapping patterns. This is somewhat non-obvious, so make a note of this in the `README`. Bumps the `th-desugar` submodule (and updates a reference to an issue number) while I'm in town. --- README.md | 22 ++++++++++++++++++++ src/Data/Singletons/Prelude/List/Internal.hs | 2 +- th-desugar | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 59cf991b..a76487bb 100644 --- a/README.md +++ b/README.md @@ -641,6 +641,28 @@ The following constructs are supported for promotion but not singleton generatio Overlap is caused by `otherwise` catch-all guard, which is always true and thus overlaps with `pred x` guard. + Another non-obvious source of overlapping patterns comes from partial pattern + matches in `do`-notation. For example: + + ```haskell + f :: [()] + f = do + Just () <- [Nothing] + return () + ``` + + This has overlap because the partial pattern match desugars to the following: + + ```haskell + f :: [()] + f = case [Nothing] of + Just () -> return () + _ -> fail "Partial pattern match in do notation" + ``` + + Here, it is more evident that the catch-all pattern `_` overlaps with the + one above it. + The following constructs are not supported: * datatypes that store arrows, `Nat`, or `Symbol` diff --git a/src/Data/Singletons/Prelude/List/Internal.hs b/src/Data/Singletons/Prelude/List/Internal.hs index fc9ad602..e15e741d 100644 --- a/src/Data/Singletons/Prelude/List/Internal.hs +++ b/src/Data/Singletons/Prelude/List/Internal.hs @@ -538,7 +538,7 @@ $(singletonsOnly [d| replicate n x = if n == 0 then [] else x : replicate (n-1) x -- Uses partial pattern-matching in a list comprehension --- (see https://github.com/goldfirere/th-desugar/issues/80) +-- (see https://github.com/goldfirere/singletons/issues/340) -- transpose :: [[a]] -> [[a]] -- transpose [] = [] -- transpose ([] : xss) = transpose xss diff --git a/th-desugar b/th-desugar index 80d08597..31584393 160000 --- a/th-desugar +++ b/th-desugar @@ -1 +1 @@ -Subproject commit 80d08597c23d4defb81d6e48d3f407bc0d91f34d +Subproject commit 31584393c854d284b981c674560ea4e97269908a