[Git][ghc/ghc][wip/or-pats] Implement Or Patterns (Proposal 0522)

David (@knothed) gitlab at gitlab.haskell.org
Fri Mar 3 12:11:00 UTC 2023



David pushed to branch wip/or-pats at Glasgow Haskell Compiler / GHC


Commits:
4c070b08 by David Knothe at 2023-03-03T13:10:28+01:00
Implement Or Patterns (Proposal 0522)

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.

- - - - -


30 changed files:

- compiler/GHC/Driver/Session.hs
- compiler/GHC/Hs/Pat.hs
- compiler/GHC/Hs/Syn/Type.hs
- compiler/GHC/Hs/Utils.hs
- compiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Pmc/Check.hs
- compiler/GHC/HsToCore/Pmc/Desugar.hs
- compiler/GHC/HsToCore/Pmc/Types.hs
- compiler/GHC/HsToCore/Utils.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Parser.y
- compiler/GHC/Parser/Annotation.hs
- compiler/GHC/Parser/Errors/Ppr.hs
- compiler/GHC/Parser/Errors/Types.hs
- compiler/GHC/Parser/Lexer.x
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Rename/Bind.hs
- compiler/GHC/Rename/Expr.hs
- compiler/GHC/Rename/Pat.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Pat.hs
- compiler/GHC/Tc/TyCl/PatSyn.hs
- compiler/GHC/Tc/Utils/Zonk.hs
- compiler/GHC/Types/Error/Codes.hs
- compiler/Language/Haskell/Syntax/Extension.hs
- compiler/Language/Haskell/Syntax/Pat.hs
- + docs/users_guide/exts/or_patterns.rst
- docs/users_guide/exts/patterns.rst
- libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs


The diff was not included because it is too large.


View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4c070b086e8bc7c79117ee3764dc0ae13ba2fa95

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4c070b086e8bc7c79117ee3764dc0ae13ba2fa95
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230303/8ce65762/attachment.html>


More information about the ghc-commits mailing list