WARNING: This server is unstable and will be retired in the next days. If you want to keep this forum available, please request immediately a migration on the Nabble Support forum. Forums that don't receive any migration request will be deleted forever.

pa_monad 1.0 - syntax extension for monads

View: New views
1 Messages — Rating Filter:   Alert me  

pa_monad 1.0 - syntax extension for monads

by Jacques Carette :: Rate this Message:

| View Threaded | Show Only this Message

We are pleased to announce the release of the stable version our syntax
extension for monadic expressions in Ocaml and MetaOCaml. As most users
of MetaOCaml know, many code generation tasks can be performed much more
nicely in monadic form (especially the continuation Monad).

All the details can be obtained from
http://www.cas.mcmaster.ca/~carette/pa_monad/ .

Example: A simple but realistic example of the use of a list monad looks
like this

       bind
         [1; 2; 3]
         (fun a -> bind
                     [3; 4; 5]
                     (fun b -> return (a + b)))

where we assume the appropriate definitions of the functions "bind" and
"return". With the help of "pa_monad" this can be written as

       perform
         a <-- [1; 2; 3];
         b <-- [3; 4; 5];
         return (a + b)

which is much clearer and thus easier to understand and maintain. By the
way, the expression evaluates to [4; 5; 6; 5; 6; 7; 6; 7; 8] the sum of
each pair of values of the input lists.

Highlights:

- Efficient code: The generated code is as efficient as hand-coded.
- Highly flexible: The "bind" and "failwith" functions can be
 specified in various ways
 (a) Binding with default names:
         perform ...
 (b) Binding with user-defined names:
         perform with my_bind and my_failwith in ...
 (c) One-of-a-kind binding:
         perform with fun a f -> f a and ... in ...
 (d) Module-based binding:
         perform with MyMonad in ...
     or with OCaml's local modules:
         let foo ... =
           let module MyMonad = ... in
           perform with MyMonad in ...

The package for this extension contains more examples as well as some
self-tests and an extensive README with yet more details (including a
patch to tuareg-mode).  In the source code (and the generated ocamldoc
html), one can find amongst other things an informal and formal
description of the grammar of the extension, and a (rewriting) semantics
for the extension.

This code is licensed under the GNU library general public license,
compatible with Ocaml's own license.

All feedback welcome,
Jacques Carette, Lydia E. van Dijk and Oleg Kiselyov

_______________________________________________
metaocaml-users-L mailing list
metaocaml-users-L@...
https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l