[Haskell-cafe] Re:Explaining monads

Brian Brunswick brian at ithil.org
Tue Aug 14 21:25:04 EDT 2007


On 15/08/07, Gregory Propf <gregorypropf at yahoo.com> wrote:
----- Original Message ----
From: Jeff Polakow <jeff.polakow at db.com>

One general intuition about monads is that they represent computations
rather than simple (already computed) values:

 I still want to re-iterate that they represent /complex/ computations -
multiple, conditional results, extra stuff etc.

Hence the need to perform a "run" operation like runIdentity, evalState or
> runParser (for Parsec) to get something useful to happen.  Except for lists
> we don't seem to do this.  I suppose lists are so simple that the operators
> :, ++ and the [] constructor do all we ever need with them.  Finally there
> is no runIO because "main" is essentially that function in every real
> program? - Greg
>


What the run functions do is unwrap the  monad. They  take apart the 'm a'
and give you back whatever a's might be
inside, and whatever extra stuff too. (Also feeding extra stuff in when m is
like that) Doing that will involve actually evaluating
the value, forcing all the data dependencies and making the 'actions'
happen.

If the monad type 'm a' is already a type we can take apart directly (list,
maybe etc.) theres no need for a run function.

Note that of course unsafePerformIO is runIO. Its just that it doesn't
really nest safely, so we like to only
use the top level one from main.

-- 
Brian_Brunswick____brian at ithil.org____Wit____Disclaimer____!Shortsig_rules!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070815/d47b58b3/attachment-0001.htm


More information about the Haskell-Cafe mailing list