* [Caml-list] ANN: BER MetaOCaml N114, for OCaml 4.14.1
@ 2023-05-12 14:04 Oleg
0 siblings, 0 replies; only message in thread
From: Oleg @ 2023-05-12 14:04 UTC (permalink / raw)
To: caml-list
BER MetaOCaml N114 is a strict superset of OCaml 4.14.1 for ``writing
programs that generate programs''. BER MetaOCaml adds to OCaml the
type of code values (denoting ``program code'', or future-stage
computations), and two basic constructs to build them: quoting and
splicing. The generated code can be printed, stored in a file -- or
compiled and linked-back to the running program, thus implementing
run-time code optimization. A subset of the generated OCaml code can
also be converted to C, via offshoring. (The generated C needs no
particular runtime or GC.) A well-typed BER MetaOCaml program
generates only well-scoped and well-typed programs: The generated code
shall compile without type errors. Staging-annotation--free BER
MetaOCaml is identical to OCaml; BER MetaOCaml can link to any
OCaml-compiled library (and vice versa).
The main changes in version N114 are
-- smoothing the path for the possible future integration into OCaml;
-- starting and almost finishing the complete solution to the
long-standing CSP problem;
-- complete support for offshoring
The problems of syntax are said to command the most discussion. This
message is no exception. In MetaOCaml, code to be generated is
enclosed in brackets: .<1 + 2>. (which may contain `holes', to be
filled with code: fun h -> .<1 + .~h>. where .~, analogous to
unquotation in Lisp, is called escape). Although `.<' and `.~' are not
valid in OCaml and hence can't be confused,
`>.' is a a valid OCaml operator (and so are the operators that start
with that character sequence, like `>..' and `>.>.'). In fact, there
are some libraries that do define the operator `>.' and which
therefore cannot be used in MetaOCaml code. Version N114 introduces an
adaptive lexer, which treats `>.' identically to ordinary OCaml, until
it sees the first `.<'. If one arranges the code such that all
occurrences of the operator `>.' come before the opening bracket, one
can use the operator even in the same file as brackets. If one cannot
arrange code such way, or must use `>.' within brackets, one has to
use the alternative syntax for brackets and escapes:
fun h -> [%metaocaml.bracket 1 >. [%metaocaml.escape h]]
although one may prefer
fun h -> [%metaocaml.bracket 1 >. .~h]
For more explanations, please see
https://okmij.org/ftp/ML/MetaOCaml.html
particularly about CSP, and
https://okmij.org/ftp/meta-programming/tutorial/genc.html
about offshoring.
See also ChangeLog and NOTES.txt in the BER MetaOCaml distribution.
BER MetaOCaml N114 should be available through OPAM, hopefully soon.
In the meanwhile, it is available as a set of patches to the
OCaml 4.14.1 distribution.
https://okmij.org/ftp/ML/ber-metaocaml.tar.gz
See the INSTALL document in that archive. You need the source
distribution of OCaml 4.14.1.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-05-12 14:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-12 14:04 [Caml-list] ANN: BER MetaOCaml N114, for OCaml 4.14.1 Oleg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox