An open API service indexing awesome lists of open source software.

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

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.