caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Harrison, William L." <harrisonwl@missouri.edu>
To: "Walid Taha" <taha@cs.rice.edu>, "Jacques Carette" <carette@mcmaster.ca>
Cc: <metaocaml-users@cs.rice.edu>, <caml-list@inria.fr>
Subject: RE: [MetaOCaml] Monads, monadic notation and OCaml
Date: Mon, 28 Mar 2005 12:39:27 -0600	[thread overview]
Message-ID: <15A1910ECFFEB943BEB04DC01FA5D08D26039B@UM-EMAIL04.um.umsystem.edu> (raw)

Hi Jacques and Walid-
 
<PLUG>
     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.
</PLUG>
 
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 = Nil | Cons of 'a * (unit -> 'a stream)
|                      | InC of (unit -> 'a stream)
|let test_nondet () =
|   let mfail = fun () -> Nil in
|   let ret a = fun () -> Cons (a,mfail) in
|   (* actually, interleave: a fair disjunction with breadth-first search*)
|   let rec mplus a b = 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 = 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 = if be then ret () else mfail in
|   let rec run n m = if n = 0 then [] else
|                 match m () with
|               | Nil -> []
|               | InC a -> run n a
|               | Cons (a,b) -> (a::run (n-1) b)
|   in
|   let rec numb () = InC (mplus (ret 0) (mdo { n <-- numb; ret (n+1) })) in
|   (* Don't try this in Prolog or in Haskell's MonadPlus! *)
|   let tst = 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 = x*x = 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



             reply	other threads:[~2005-03-28 18:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-28 18:39 Harrison, William L. [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-03-28  2:31 Jacques Carette
2005-03-28 18:17 ` [MetaOCaml] " Walid Taha
2005-03-28 18:40   ` Jacques Carette

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15A1910ECFFEB943BEB04DC01FA5D08D26039B@UM-EMAIL04.um.umsystem.edu \
    --to=harrisonwl@missouri.edu \
    --cc=caml-list@inria.fr \
    --cc=carette@mcmaster.ca \
    --cc=metaocaml-users@cs.rice.edu \
    --cc=taha@cs.rice.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).