Skip to content

Commit

Permalink
Draft: Adapt to (but don't fully support) Or-patterns
Browse files Browse the repository at this point in the history
TODO RGS: Explain why, cite issue
  • Loading branch information
RyanGlScott committed Aug 2, 2024
1 parent df957ef commit b60b71f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Version 1.18 [????.??.??]
-------------------------
* Support GHC 9.12.
* The `DLamE` and `DCaseE` data constructors (as well as the related
`mkDLamEFromDPats` function) are now deprecated in favor of the new
`DLamCasesE` data constructor. `DLamE`, `DCaseE`, and `mkDLamEFromDPats` will
Expand Down
4 changes: 4 additions & 0 deletions Language/Haskell/TH/Desugar/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,10 @@ dsPat (InvisP ty) = DInvisP <$> dsType ty
#endif
dsPat (ViewP _ _) =
fail "View patterns are not supported in th-desugar. Use pattern guards instead."
#if __GLASGOW_HASKELL__ >= 911
dsPat (OrP _) =
fail "Or-patterns are not supported in th-desugar. Use pattern guards instead."
#endif

-- | Convert a 'DPat' to a 'DExp'. Fails on 'DWildP' and 'DInvisP'.
dPatToDExp :: DPat -> DExp
Expand Down
3 changes: 3 additions & 0 deletions Language/Haskell/TH/Desugar/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,9 @@ extractBoundNamesPat (UnboxedSumP pat _ _) = extractBoundNamesPat pat
extractBoundNamesPat (TypeP _) = OS.empty
extractBoundNamesPat (InvisP _) = OS.empty
#endif
#if __GLASGOW_HASKELL__ >= 911
extractBoundNamesPat (OrP pats) = foldMap extractBoundNamesPat pats
#endif

----------------------------------------
-- General utility
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,12 @@ potentially recognize this and perform a more sophisticated analysis to detect
and remove such matches when desugaring guards, but it currently doesn't do
such an analysis.

## No support for view patterns
## No support for view patterns or Or-patterns

`th-desugar` does not support desugaring view patterns or Or-patterns. An
alternative to using view patterns or Or-patterns in the patterns of a function
is to use pattern guards.

`th-desugar` does not support desugaring view patterns. An alternative to using
view patterns in the patterns of a function is to use pattern guards.
Currently, there is not a viable workaround for using view patterns in pattern
synonym definitions—see [this `th-desugar`
issue](https://github.com/goldfirere/th-desugar/issues/174).
Expand Down

0 comments on commit b60b71f

Please sign in to comment.