# [Haskell-cafe] Re: Converting IO [XmlTree] to [XmlTree]

Achim Schneider 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?
>
unsafeCoerce.

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) do 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.

that, the Typeclassopedia[2].

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.