package ppx_viewpattern

  1. Overview
  2. Docs
View patterns in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_viewpattern-0.1.0.tbz
sha256=826e53c910e1255698e2988e1055f5dc173a4f3fb6cd92346f62d0b3d0e05c7b
sha512=c7011376ff879bd0a64f5c92ee23dd1734ede7ade623491b6c80e8f9d00871718bcf998f8950727f0e9e176e3a4e864fcad52e3995e71b53ab1c19de43643250

Description

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

Published: 14 Mar 2022

README

ppx_viewpattern

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

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

Dependencies (2)

  1. ppxlib >= "0.9.0"
  2. dune >= "2.8"

Dev Dependencies (3)

  1. odoc with-doc
  2. qcheck-ounit with-test
  3. ounit2 with-test

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.