caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: John Prevost <prevost@maya.com>
To: "Frank A. Christoph" <christo@nextsolution.co.jp>
Cc: "CAML Mailing list" <caml-list@inria.fr>
Subject: Re: A propos de monad/About monads
Date: 04 Oct 1999 14:55:33 -0400	[thread overview]
Message-ID: <m3ln9j2bx6.fsf@isil.maya.com> (raw)
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.




  parent reply	other threads:[~1999-10-05  8:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-30 16:24 A propos de monad Stéphane Baubillier
1999-10-01  7:17 ` David Gross
1999-10-01  9:26 ` A propos de monad/About monads David Mentr'e
1999-10-02 18:10   ` David Brown
1999-10-04  8:40   ` Frank A. Christoph
1999-10-04 14:46     ` Frank A. Christoph
1999-10-04 21:20       ` Jan Skibinski
1999-10-04 18:55     ` John Prevost [this message]
1999-10-05  5:48       ` Frank A. Christoph

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=m3ln9j2bx6.fsf@isil.maya.com \
    --to=prevost@maya.com \
    --cc=caml-list@inria.fr \
    --cc=christo@nextsolution.co.jp \
    /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).