diff options
author | David Knothe <dknothe314@me.com> | 2022-10-25 09:18:26 +0200 |
---|---|---|
committer | David Knothe <dknothe314@me.com> | 2023-03-03 13:10:28 +0100 |
commit | 4c070b086e8bc7c79117ee3764dc0ae13ba2fa95 (patch) | |
tree | 615838a3d5016d8f8c11ae6dc00bff9e4948ce5e /compiler/GHC/Driver/Session.hs | |
parent | 2f97c86151d7eed115ddcbdee1842684aed63176 (diff) | |
download | haskell-wip/or-pats.tar.gz |
Implement Or Patterns (Proposal 0522)wip/or-pats
This commit introduces a language extension, `OrPatterns`, as described in proposal 0522.
It extends the syntax by the production
`pat -> (one of pat1, ..., patk)`.
The or-pattern `pat` succeeds iff one of the patterns `pat1`, ..., `patk` succeed, in this order.
Currently, or-patterns cannot bind variables. They are still of great use as they discourage the use of wildcard patterns in favour of writing out all "default" cases explicitly:
```
isIrrefutableHsPat pat = case pat of
...
(one of WildPat{}, VarPat{}, LazyPat{})
= True
(one of PArrPat{}, ConPatIn{}, LitPat{}, NPat{}, NPlusKPat{}, ListPat{})
= False
```
This makes code safer where data types are extended now and then - just like GHC's `Pat` in the example when adding the new `OrPat` constructor. This would be catched by `-fwarn-incomplete-patterns`, but not when a wildcard pattern was used.
- Update submodule haddock.
Diffstat (limited to 'compiler/GHC/Driver/Session.hs')
-rw-r--r-- | compiler/GHC/Driver/Session.hs | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs index 2ad09bc7c6..c544b398a7 100644 --- a/compiler/GHC/Driver/Session.hs +++ b/compiler/GHC/Driver/Session.hs @@ -3703,6 +3703,7 @@ xFlagsDeps = [ depFlagSpec' "NullaryTypeClasses" LangExt.NullaryTypeClasses (deprecatedForExtension "MultiParamTypeClasses"), flagSpec "NumDecimals" LangExt.NumDecimals, + flagSpec "OrPatterns" LangExt.OrPatterns, depFlagSpecOp "OverlappingInstances" LangExt.OverlappingInstances setOverlappingInsts "instead use per-instance pragmas OVERLAPPING/OVERLAPPABLE/OVERLAPS", |