A propos de monad
[
Home
]
[ Index:
by date

by threads
]
[ Message by date: previous  next ] [ Message in thread: previous  next ] [ Thread: previous  next ]
[ Message by date: previous  next ] [ Message in thread: previous  next ] [ Thread: previous  next ]
Date:  19991005 (08:12) 
From:  John Prevost <prevost@m...> 
Subject:  Re: A propos de monad/About monads 
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 sideeffects. > > Also, I often use monads in Haskell which have no sideeffects at all. For > example, I might use a nonimperative 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 > sideeffects either. I spent some time last year working with monadic parsersthis 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 higherorder combinator stuff for, as an example, formatted printing) doesn't work that well in ML because of the value restriction. :( John.