package ppx_monoid

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

Install

Dune Dependency

Authors

Maintainers

Sources

v0.3.3.tar.gz
md5=a3080fb7b473bfebcb8724b53df1c27f
sha512=b2ac2c291dd0ade2aad61d78a5dd82a2dc4fd51d5455f4419481c2c26e2acb26753926a2581f55f2bd2b10b25159e7d7b87f5fef67b5315d799d2a86de359f50

Description

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.

Published: 29 Jul 2022

README

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.

Dependencies (3)

  1. ppxlib >= "0.27.0"
  2. ocaml >= "4.04.1"
  3. dune >= "2.7"

Dev Dependencies (2)

  1. odoc with-doc
  2. ounit with-test

Used by

None

Conflicts

None