package ppx_optional

  1. Overview
  2. Docs
Pattern matching on flat options

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_optional-v0.9.0.tar.gz
sha256=0c4f54f42075c0f337bbf12e89d74c29cc68fa285ba3fc6fbf4a37c1c6f2aa4e
md5=84dfad9aa7e326f00d12101c8c353e2b

Description

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

Published: 22 Mar 2017

README

title: ppx_optional - match statements for zero-alloc options parent: ../README.md

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 unchecked_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.unchecked_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 (6)

  1. ocaml-migrate-parsetree >= "0.4" & < "2.0.0"
  2. ppx_metaquot >= "v0.9" & < "v0.10"
  3. ppx_driver >= "v0.9" & < "v0.10"
  4. ppx_core >= "v0.9" & < "v0.10"
  5. jbuilder >= "1.0+beta4"
  6. ocaml >= "4.03.0"

Dev Dependencies

None

Used by (1)

  1. ppx_jane = "v0.9.0"

Conflicts

None

OCaml

Innovation. Community. Security.