[wg-camlp4] My P4 uses
Jun Furuse
jun.furuse at gmail.com
Tue Jan 29 15:03:41 GMT 2013
Hi,
Here are the things I do with CamlP4. Lots are just simple variants of
the already reported things, though.
pa_monad for "perform" notation
===================================
URL: https://bitbucket.org/camlspotter/pa_monad_custom
I modified the original pa_monad so that I can write I/O code easily inside
perform:
perform
...;
let () = prerr_endline "debug" in (* Writing let () = ... in is
boring *)
...;
peform
...;
\ prerr_endline "debug"; (* It is not unit monad, but a
simple unit *)
...;
Here \ behaves like a prefix operator with very low power,
less than function application.
I wish -ppx could provide an easy way to handle those operators with
custom connectivity configurations, including pa_monad's <--.
Code generations from data type definitions
======================================================
I have bunch of type_conv based pa modules, such as meta_conv, and other
iterator/visitor/mapper generators. I believe they can be easily ported
from
type_conv to -ppx, if we could do for sexplib.
Record like syntax
======================================================
URL: https://bitbucket.org/camlspotter/ocaml-pure-polyrecord
I introduced record like syntax for pure polymorphic records
(they are not objects so they can be marshalled). The syntax is like:
let r = {| x = 1; y = "hello"; |}
let x = r..x
So this is a variant of js_of_ocaml's javascript object syntax.
Perl/Python/Shell like string literals
======================================================
URL: https://bitbucket.org/camlspotter/orakuda
ORakuda provides some scripting language like string literals like:
$/^(.*)\.mli$/ (* Regexp. See \ is
not doubled. *)
$s/template/replace/g
let myname = "Jun" in $"My name is $myname and my age is %d" 42
(* printf *)
let dir = Sys.getenv "HOME" in $`ls $dir`
It is very useful to write quick one time OCaml scripts, however, it
requires
a patch to CamlP4 to modify its lexer. CamlP4 can actually replace its
lexer, but
it is not integrated into pa_*.cmo framework.
So without the patch, the above must be written:
<:m<^(.*)\.mli$>>
<:s<template/replace/g>>
let myname = "Jun" in <:qq<My name is $myname and my age is %d>> 42
let dir = Sys.getenv "HOME" in <:qx<ls $dir>>
It is a bit cumbersome to type <:< >> around, but still they are useful to
me.
Note that $ is NOT used as anti-quotation for these quotes.
So I think fixing anti-quotation symbol to some character like $
uniformly is a bad idea.
I do not expect -ppx is going to handle lexer hacks like $/.../, however,
I hope it could be simple enough to write a patch to support $/.../. :-)
Partial evaluation
======================================================
In Planck LL parser library, I wrote a small pa module to partial-evaluate
monadic binds for optimzation. This is purely a program transformation,
so there should be no problem to do the same thing in -ppx.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ocaml.org/pipermail/wg-camlp4/attachments/20130129/12b179b0/attachment.html>
More information about the wg-camlp4
mailing list