From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id ED286BB84 for ; Wed, 7 Jun 2006 21:36:33 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k57JaXur002428 for ; Wed, 7 Jun 2006 21:36:33 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA25628 for ; Wed, 7 Jun 2006 21:36:32 +0200 (MET DST) Received: from sigma957.cis.mcmaster.ca (sigma957.CIS.McMaster.CA [130.113.64.83]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k57JaVIM015279 for ; Wed, 7 Jun 2006 21:36:31 +0200 Received: from cgpsrv2.cis.mcmaster.ca (univmail.CIS.McMaster.CA [130.113.64.46]) by sigma957.cis.mcmaster.ca (8.13.4/8.13.4) with ESMTP id k57JaCm8015168; Wed, 7 Jun 2006 15:36:26 -0400 (EDT) Received: from [69.193.76.85] (account carette@univmail.cis.mcmaster.ca HELO [192.168.1.101]) by cgpsrv2.cis.mcmaster.ca (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 128621213; Wed, 07 Jun 2006 15:36:25 -0400 Message-ID: <44872ABF.2020307@mcmaster.ca> Date: Wed, 07 Jun 2006 15:36:31 -0400 From: Jacques Carette Organization: McMaster University User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: caml-list@inria.fr Cc: oleg@pobox.com, lvandijk@freenet.de Subject: pa_monad 1.0 - syntax extension for monads Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-PMX-Version-Mac: 4.7.1.128075, Antispam-Engine: 2.1.0.0, Antispam-Data: 2006.6.7.113432 X-PerlMx-Spam: Gauge=IIIIIII, Probability=7%, Report='__CP_URI_IN_BODY 0, __CT 0, __CTE 0, __CT_TEXT_PLAIN 0, __HAS_MSGID 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __SANE_MSGID 0, __USER_AGENT 0' X-Miltered: at concorde with ID 44872AC1.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 44872ABF.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; syntax:01 monads:01 syntax:01 monadic:01 ocaml:01 failwith:01 failwith:01 ocaml's:01 foo:01 ocamldoc:01 grammar:01 rewriting:01 semantics:01 ocaml's:01 oleg:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 We are pleased to announce the release of the stable version our syntax extension for monadic expressions in Ocaml. 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