[Haskell-cafe] Properties of monads

Radosław Grzanka radoslawg at gmail.com
Mon Nov 19 16:08:39 EST 2007

Hi Benja,

> Something like the following might feel cleaner, though:
> maybeT :: Maybe a -> MaybeT m a
> maybeT = MaybeT . return
> downloadFile :: String -> MaybeT IO String
> downloadFile s = maybeT (parseURI s) >>= liftIO . httpGet

This is even neater. However, I fail to implement this. It does not
compile and although I spent few hours trying to figure out correct
usage of transformers I still fail to solve this.

Here are types of expressions

parseURI :: String -> Maybe URI
httpGet :: URI -> IO (Maybe String)
maybeT parseURI :: (Monad m) => String -> MaybeT m Network.URI.URI

So far so good. However:

liftIO . httpGet :: (Control.Monad.Trans.MonadIO m) => Network.URI.URI
-> m (Maybe String)

so it gives different type than is required here because httpGet
already returns IO Maybe String. So I would need transformation from
IO ( Maybe a) -> MaybeT IO a . Is there such possibility?

Thank you for your spent time on this.


Codeside: http://codeside.org/
Przedszkole Miejskie nr 86 w Lodzi: http://www.pm86.pl/

More information about the Haskell-Cafe mailing list