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 /utils/haddock | |
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 'utils/haddock')
m--------- | utils/haddock | 0 |
1 files changed, 0 insertions, 0 deletions
diff --git a/utils/haddock b/utils/haddock -Subproject 519a95998b09a2c9c7a42c3a0cf2ca0c4358bb4 +Subproject f9ddb2eba372cf3c2446d61658985ae5d3dc19d |