https://github.com/leviroth/ppx_constr_test
Test if a variant matches a given constructor
https://github.com/leviroth/ppx_constr_test
Last synced: 10 months ago
JSON representation
Test if a variant matches a given constructor
- Host: GitHub
- URL: https://github.com/leviroth/ppx_constr_test
- Owner: leviroth
- Created: 2018-01-01T03:49:04.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-02T22:30:08.000Z (over 8 years ago)
- Last Synced: 2025-03-03T07:41:40.591Z (over 1 year ago)
- Language: OCaml
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This simple ppx rewriter allows you to test if a variant instance matches a
given constructor. `[%constr_test ] x` returns true iff
`` is the constructor of `x`. For example,
```ocaml
[%constr_test None] None = true
[%constr_test None] (Some 1) = false
[%constr_test Some __] (Some 1) = true
[%constr_test Some __] None = false
```
For constructors that take arguments, an argument pattern such as `__` must be
included; otherwise, the rewriter cannot infer the arity of the constructor.