package ppx_monoid
Install
Dune Dependency
Authors
Maintainers
Sources
md5=de413a86ef336834a30e9f53c6794d81
sha512=3b594411e424c2db7d3c3edf62fb1ac04f0a24b3aaf20f9df47eaa43fc696b72ec0b66ee94f824a1c5148bf93fe133c605430fe5e7ddf2df5e694ca4ec7724a8
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: 17 Jan 2020
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 (4)
-
ppx_tools_versioned
>= "5.2.3"
-
ocaml-migrate-parsetree
>= "1.5.0" & < "2.0.0"
-
ocaml
>= "4.04.0"
-
dune
>= "2.0"
Dev Dependencies (1)
-
ounit
with-test
Used by
None
Conflicts
None