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