Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sim642/ppx_viewpattern
View patterns in OCaml
https://github.com/sim642/ppx_viewpattern
ocaml ppx ppx-rewriter ppxlib
Last synced: about 2 months ago
JSON representation
View patterns in OCaml
- Host: GitHub
- URL: https://github.com/sim642/ppx_viewpattern
- Owner: sim642
- License: mit
- Created: 2022-02-27T21:24:40.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-28T19:41:48.000Z (over 2 years ago)
- Last Synced: 2024-04-15T04:17:23.180Z (8 months ago)
- Topics: ocaml, ppx, ppx-rewriter, ppxlib
- Language: OCaml
- Homepage:
- Size: 48.8 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ppx_viewpattern
[![ci workflow status](https://github.com/sim642/ppx_viewpattern/actions/workflows/ci.yml/badge.svg)](https://github.com/sim642/ppx_viewpattern/actions/workflows/ci.yml)
[![GitHub release status](https://img.shields.io/github/v/release/sim642/ppx_viewpattern)](https://github.com/sim642/ppx_viewpattern/releases)
[![opam package status](https://badgen.net/opam/v/ppx_viewpattern)](https://opam.ocaml.org/packages/ppx_viewpattern)Transformation for view patterns in OCaml.
_Attempts to_ imitate [Haskell view patterns](https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/view_patterns.html).## Installation
```console
opam install ppx_viewpattern
```## Usage
In dune:
```
(preprocess (pps ppx_viewpattern))
```## Syntax
Use `[%view? pat when exp]` as a pattern to apply `exp` to whatever the pattern is matching and match the result of the `exp` application against `pat`.
Analogous to the Haskell view pattern `exp -> pat`.See [`example/`](example/) for example usage.
Supported in:
* `match ... with ...` cases,
* `function ...` cases,
* `fun ... -> ...` arguments,
* `let ... in ...` expression binding left-hand sides,
* `try ... with ...` cases,
* nested inside the `pat` and `exp` parts of a view pattern itself.### Caveats
A view pattern disables `redundant-case` and `partial-match` warnings for the corresponding `match`/`function`.Currently unsupported in:
- `let ...` definition left-hand sides (at top level or in modules).