From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 9A71BBC84 for ; Mon, 28 Mar 2005 20:39:31 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j2SIdVmQ018958 for ; Mon, 28 Mar 2005 20:39:31 +0200 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id UAA05475 for ; Mon, 28 Mar 2005 20:39:30 +0200 (MET DST) Received: from um-exproto8.um.umsystem.edu (um-exproto8.um.umsystem.edu [207.160.151.48]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j2SIdTO8003512 for ; Mon, 28 Mar 2005 20:39:30 +0200 Received: from UM-EMAIL04.um.umsystem.edu ([207.160.151.17]) by um-exproto8.um.umsystem.edu with Microsoft SMTPSVC(6.0.3790.211); Mon, 28 Mar 2005 12:39:28 -0600 x-mimeole: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [MetaOCaml] Monads, monadic notation and OCaml Date: Mon, 28 Mar 2005 12:39:27 -0600 Message-ID: <15A1910ECFFEB943BEB04DC01FA5D08D26039B@UM-EMAIL04.um.umsystem.edu> Thread-Topic: [MetaOCaml] Monads, monadic notation and OCaml Thread-Index: AcUzwrdXP92+Hh+pQN2DtxA8VWVmEQAAUnwv From: "Harrison, William L." To: "Walid Taha" , "Jacques Carette" Cc: , X-OriginalArrivalTime: 28 Mar 2005 18:39:28.0347 (UTC) FILETIME=[791D62B0:01C533C5] X-Miltered: at nez-perce with ID 42484F63.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 42484F61.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; metaocaml:01 monads:01 monadic:01 notation:01 ocaml:01 posts:01 monads:01 drafts:01 haskell:01 walid:01 taha:01 caml-list:01 metaocaml:01 monadic:01 notation:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: Hi Jacques and Walid- =20 I've been reading your recent posts, and given the interest in = stream (a.k.a. resumption) monads, I thought you might be interested in = a draft I've submitted about the use of just such monads: = http://www.cs.missouri.edu/~harrison/drafts/CheapThreads.pdf This article describes the construction of a multitasking operating = system kernel in Haskell 98 using resumption monads; the kernel has all = the "usual" OS behaviors (e.g., process forking, preemption, message = passing, synchronization, etc.) captured succintly. =20 Bill ________________________________ From: metaocaml-users-l-bounces@mailman.rice.edu on behalf of Walid Taha Sent: Mon 3/28/2005 12:17 PM To: Jacques Carette Cc: metaocaml-users@cs.rice.edu; caml-list@inria.fr Subject: Re: [MetaOCaml] Monads, monadic notation and OCaml This is pretty cool! Are you using the same monad we used in the FFT work? Also, can you either get rid of the ";" after the "in" or the "in" = before the ";"? :) Walid. On Sun, 27 Mar 2005, Jacques Carette wrote: |Attached is a camlp4 syntax extension for a 'monadic do notation' for = OCaml, much like Haskell's. The syntax |extension is joint work with Oleg Kiselyov, and is loosely based on = previous work of Lydia van Dijk on a similar |syntax extension. | |Naturally, in OCaml certain monads (like State and IO) are unnecessary. = But other monads (List, option, etc) can be |quite convenient. | |But monads can be much more than convenient. Below is some code = written in a non-deterministic monad of streams. |This example is particularly interesting in that it cannot be (naively) = done in either Prolog or in Haskell's |MonadPlus monad, both of which would go into an infinite loop on this = example. | |(* test non-determinism monad, the simplest possible implementation *) |type 'a stream =3D Nil | Cons of 'a * (unit -> 'a stream) | | InC of (unit -> 'a stream) |let test_nondet () =3D | let mfail =3D fun () -> Nil in | let ret a =3D fun () -> Cons (a,mfail) in | (* actually, interleave: a fair disjunction with breadth-first = search*) | let rec mplus a b =3D fun () -> match a () with | | Nil -> InC b | | InC a -> (match b () with | | Nil -> InC a | | InC b -> InC (mplus a b) | | Cons (b1,b2) -> Cons (b1, (mplus a b2))) | | Cons (a1,a2) -> Cons (a1,(mplus b a2)) in | (* a fair conjunction *) | let rec bind m f =3D fun () -> match m () with | | Nil -> mfail () | | InC a -> InC (bind a f) | | Cons (a,b) -> mplus (f a) (bind b f) () in | let guard be =3D if be then ret () else mfail in | let rec run n m =3D if n =3D 0 then [] else | match m () with | | Nil -> [] | | InC a -> run n a | | Cons (a,b) -> (a::run (n-1) b) | in | let rec numb () =3D InC (mplus (ret 0) (mdo { n <-- numb; ret (n+1) = })) in | (* Don't try this in Prolog or in Haskell's MonadPlus! *) | let tst =3D mdo { | i <-- numb; | guard (i>0); | j <-- numb; | guard (j>0); | k <-- numb; | guard (k>0); | (* Just to illustrate the `let' form within mdo *) | let test x =3D x*x =3D j*j + k*k in; | guard (test i); | ret (i,j,k) | } | in run 7 tst |;; | |We ourselves have been experimenting with a combined state-passing, = continuation-passing monad, where the values |returned and manipulated are code fragments (in MetaOCaml). This = allows for considerably simpler, typed code |combinators. Details of this work will be reported elsewhere. | |Jacques | | |!DSPAM:42476c8f13209207723021! | _______________________________________________ metaocaml-users-L mailing list metaocaml-users-L@mailman.rice.edu https://mailman.rice.edu/mailman/listinfo/metaocaml-users-l