package ppx_pattern_guard

  1. Overview
  2. No Docs
ppx_pattern_guard: ppx extension for pattern guard

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_pattern_guard-1.0.1.tar.gz
sha256=0ef2e2ef1cfe413d9c08067efb4fbe28d0585700215c4117d9bc0d2a03532f5e
md5=6e2902dfa2fe8d0e7ccaebba9ce867b6

Description

Pattern guards in OCaml

This ppx adds (pattern guards)[http://citeseer.ist.psu.edu/erwig00pattern.html] to OCaml. This is inspired by (ocaml-patterns)[http://code.google.com/p/ocaml-patterns/wiki/PatternGuards], an old CamlP4 extension for pattern guards, but is an independent implementation.

Pattern guard when [%guard <guards>]

Pattern guard is an extension of OCaml guard (or boolean guard) when e in match, function and try cases. (Do not be confused with guards (boolean guards) and pattern guards.)

While when e only takes a boolean expression e to have an additional test to a case, when [%guard let p = e] can take a pattern match: if e's value matches with the pattern p, the case is selected, and the variables in the pattern p are bound in the case action, the right hand side of ->. If the value does not match, the case is skipped.

In [%guard <guards>], pattern guards (let p = e) and boolean guards (e) can be sequenced like [%guard let y = f x;; p(y)]. They are tested in their appearence order. The bound variables in pattern guards can be used in the later pattern guards and boolean guards, in addition to the case action.

Example

match e with
| (x, y) when [%guard let w = x + y;; w = 5] -> prerr_endline "3"

Published: 05 Nov 2014

Dependencies (3)

  1. omake
  2. ocamlfind
  3. ocaml = "4.02.1"

Dev Dependencies

None

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.