[Haskell-cafe] Re: Converting IO [XmlTree] to [XmlTree]
barsoap at web.de
Tue Apr 14 12:13:49 EDT 2009
"rodrigo.bonifacio" <rodrigo.bonifacio at uol.com.br> wrote:
> Dear Sirs,
> I guess this is a very simple question. How can I convert IO
> [XmlTree] to just a list of XmlTree?
Seriously, you just don't, you weld stuff together using >>=. It takes
an 'IO a' and a function 'a -> IO b' and returns you an 'IO b', thus
preventing you from launching nuclear missiles while you're standing in
front of the exhaust jets. You don't want to be able to.
do-notation is a convenient short-hand:
foo >>= (\bar -> return $ baz bar)
bar <- foo
return $ baz bar
>>= doesn't only work with IO, but with any monad, that's why it's type,
(>>=) :: Monad m => m a -> (a -> m b) -> m b
might look intimidating, but actually isn't.
For more info, have a look at Real World Haskell, and, after
that, the Typeclassopedia.
As a final notice, don't listen to the others: Those are just desperate
people, vainly trying to convince themselves they'd understand monads.
If you see monads being compared to space suits, nuclear waste
processing plants, or burritos, run far, run fast, but run. If you see
them compared to applicative functors, get curious.
(c) this sig last receiving data processing entity. Inspect headers
for copyright history. All rights reserved. Copying, hiring, renting,
performance and/or quoting of this signature prohibited.
More information about the Haskell-Cafe