comp CamlTrax
This page is about CamlTrax, a layout preprocessor for OCaml.

Introduction

OCaml is a fantastic programming language, but I, like many Haskellers, wish it had layout-based parsing to avoid all the parens. A friend recently introduced me to OCaml+TWT, a layout preprocessor for OCaml, but I don't like how it handles layout, and I have trouble, e.g., reading nested "if"s. So, I wrote CamlTrax, my own preprocessor. It is at least as retarded as OCaml+TWT, but in a way that I find less irritating.

News
Download
Demonstrations

Part of the source code for CamlTrax.
while (snd $ Stack.top st) <> lparenF
      do emit $ rparen $ Stack.top st ;     
         ignore $ Stack.pop st ;
if (snd $ Stack.top st) = lparenF
   then emit $ rparen $ Stack.top st ;
        ignore $ Stack.pop st ;
advance t
Generated OCaml equivalent.
(* Generated by                  *
 *             CamlTrax          *
 *                     Version 3 *)
( while (snd ( Stack.top st )) <> lparenF
do emit ( rparen ( Stack.top st ;      ) )
ignore ( Stack.pop st  ) done );
( if (snd ( Stack.top st )) = lparenF
then ( emit ( rparen ( Stack.top st  ) );
ignore ( Stack.pop st  ) ) );
advance t

Composition & infix application.
fun env -> map $ second $ drop . eval env . lift     
Generated OCaml equivalent.
(* Generated by                  *
 *             CamlTrax          *
 *                     Version 3 *)
fun env -> map ( second ( drop ++ eval env ++ lift ) )

Nested "if"s.
if is_tcon c
   then KType
   else if is_pcon c
           then KProp
           else raise $ TypeError "Kind error."     
Generated OCaml equivalent.
(* Generated by                  *
 *             CamlTrax          *
 *                     Version 3 *)
( if is_tcon c
then ( KType )
else ( ( if is_pcon c
then ( KProp )
else ( raise ( TypeError "Kind error." ) ) ) ) )

More Information

If you decide to try out CamlTrax, there are a few things you should keep in mind.

back

This page was generated by WebGen on PhoenixFyre on Fri Sep 26 10:31:41 EDT 2008.