From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: weis Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA07952 for caml-redistribution; Tue, 5 Oct 1999 10:12:50 +0200 (MET DST) 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 UAA32021 for ; Mon, 4 Oct 1999 20:50:32 +0200 (MET DST) Received: from isil.maya.com (isil.maya.com [192.70.254.5]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id UAA19754 for ; Mon, 4 Oct 1999 20:50:29 +0200 (MET DST) Received: (from prevost@localhost) by isil.maya.com (8.9.3/8.9.3) id OAA00954; Mon, 4 Oct 1999 14:55:33 -0400 Sender: weis To: "Frank A. Christoph" Cc: "CAML Mailing list" Subject: Re: A propos de monad/About monads References: <000201bf0e44$11bfa300$0150ebca@nextsolution.co.jp> From: John Prevost 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" Message-ID: User-Agent: Gnus/5.070096 (Pterodactyl Gnus v0.96) Emacs/20.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Frank A. Christoph 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.