Skip to content

Commit

Permalink
Make note of #340 in the README
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RyanGlScott committed Jun 17, 2018
1 parent 56e4676 commit 71b702e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion src/Data/Singletons/Prelude/List/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 71b702e

Please sign in to comment.