sim642 / ppx_viewpattern

View patterns in OCaml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ppx_viewpattern

ci workflow status GitHub release status opam package status

Transformation for view patterns in OCaml. Attempts to imitate Haskell view patterns.

Installation

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/ 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).

About

View patterns in OCaml

License:MIT License


Languages

Language:OCaml 92.8%Language:Standard ML 7.2%