package ppx_monoid

  1. Overview
  2. Docs
Syntax extension for building values of monoids

Install

Dune Dependency

Authors

Maintainers

Sources

0.3.2.tar.gz
md5=de413a86ef336834a30e9f53c6794d81
sha512=3b594411e424c2db7d3c3edf62fb1ac04f0a24b3aaf20f9df47eaa43fc696b72ec0b66ee94f824a1c5148bf93fe133c605430fe5e7ddf2df5e694ca4ec7724a8

README.md.html

ppx-monoid

This is a syntax extension for OCaml to make building values of monoids easier. Assumes the existence of two operations in scope for some type t:

empty : t
(^^)  : t -> t -> t

ppx-monoid, triggered by the PPX extension point monoid, reinterprets the semicolon ; to mean the monoid operation ^^ and the unit expression () to mean empty.

Example:

let empty = "" and (^^) = (^) in
begin%monoid
  "hello";
  " ";
  "world"
end

is translated to:

let empty = "" and (^^) = (^) in
"hello" ^^ " " ^^ "world"

It is also possible to use concat or concatenate instead of monoid:

let empty = "" and (^^) = (^) in
begin%concat   (* or 'concatenate' *)
  "hello";
  " ";
  "world"
end

See the test/test.ml file for more examples of usage, and for examples of how the translation interacts with if then else and match expressions.

The main use case for this syntax extension is for writing code that generates HTML which consists of long sequences of concatenated bits of HTML.

OCaml

Innovation. Community. Security.