**Next message:**Jan Skibinski: "RE: A propos de monad/About monads"**Previous message:**Jun P. Furuse: "Re: mmm for ocaml2?"**Maybe in reply to:**Haruo Hosoya: "mmm for ocaml2?"**Messages sorted by:**[ date ] [ thread ] [ subject ] [ author ]

To: "Frank A. Christoph" <christo@nextsolution.co.jp>

Subject: Re: A propos de monad/About monads

From: John Prevost <prevost@maya.com>

Date: 04 Oct 1999 14:55:33 -0400

In-Reply-To: "Frank A. Christoph"'s message of "Mon, 4 Oct 1999 17:40:10 +0900"

Frank A. Christoph <christo@nextsolution.co.jp> writes:

*> But monads are also used in Opal, which is an eager language, to keep the
*

*> base language pure from side-effects.
*

*>
*

*> Also, I often use monads in Haskell which have no side-effects at all. For
*

*> example, I might use a non-imperative state transformer to "lay out the
*

*> plumbing" for an algorithm, i.e., to avoid passing variables around
*

*> explicitly; the error monad, which is a monad over what in Ocaml corresponds
*

*> to the option type (functor), is also extremely useful, and has no
*

*> side-effects either.
*

I spent some time last year working with monadic parsers--this is

another really nice way to use monads (especially if you have monad

comprehensions.) An example, using something like what I wrote to do

Monad comprehensions in camlp4:

let char c = << x | x <- item; x = c >>

let digit = << x | x <- item; x >= '0' && x <= '9' >>

let rec many p = << x::xs | x <- p; xs <- many p >>

let number = many digit

let bracket l p r = << x | _ <- l; x <- p; _ <- r >>

let rec seq p s = << x :: xs | x <- p; _ <- s; xs <- seq p s >>

|-| << [x] | x <- p >>

let number_list = bracket (char '[') (seq number (char ',')) (char ']')

And then number_list would parse something like "[1,2,3,4,56]" into

the Caml value [1; 2; 3; 4; 56].

Unfortunately, this kind of thing (along with other higher-order

combinator stuff for, as an example, formatted printing) doesn't work

that well in ML because of the value restriction. :(

John.

**Next message:**Jan Skibinski: "RE: A propos de monad/About monads"**Previous message:**Jun P. Furuse: "Re: mmm for ocaml2?"**Maybe in reply to:**Haruo Hosoya: "mmm for ocaml2?"**Messages sorted by:**[ date ] [ thread ] [ subject ] [ author ]

*
This archive was generated by hypermail 2b29
: Sun Jan 02 2000 - 11:58:26 MET
*