package ppx_optional

  1. Overview
  2. Docs
Pattern matching on flat options

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_optional-v0.11.0.tar.gz
sha256=10f4436eb5e393a9cf58c14e229a9ccf6f101e7d4e5249f5dc6296a4de121ffd
md5=27bcae8445af584299876bdab0288152

Description

A ppx rewriter that rewrites simple match statements with an if then else expression.

Published: 22 Mar 2018

README

ppx_optional - match statements for zero-alloc options

A ppx rewriter that rewrites simple match statements with an if then else expression.

Syntax

ppx_optional rewrites the extension match%optional in expressions. It requires that a module Optional_syntax is in scope, and that it has is_none and unsafe_value values.

For instance:

match%optional e with
| None -> none_expression
| Some x -> some_expression

becomes:

if Optional_syntax.is_none e then begin
   none_expression
end else begin
   let x = Optional_syntax.unsafe_value e in
   some_expression
end

Usage

This is normally used to safely access an optional value while avoiding allocation for immediate values (e.g. Immediate.{Char,Bool,Int}.Option, Fixed.Option, Price.Fixed.Option, etc...).

Dependencies (5)

  1. ppxlib >= "0.1.0" & < "0.9.0"
  2. ocaml-migrate-parsetree >= "1.0" & < "2.0.0"
  3. jbuilder >= "1.0+beta18.1"
  4. base >= "v0.11" & < "v0.12"
  5. ocaml >= "4.04.1"

Dev Dependencies

None

Used by (1)

  1. ppx_jane = "v0.11.0"

Conflicts (1)

  1. jbuilder = "1.0+beta19"
OCaml

Innovation. Community. Security.