[Haskell-beginners] combining two monads

Ozgur Akgun ozgurakgun at gmail.com
Tue Aug 23 13:53:48 CEST 2011


Hi.

Daniel already answered the question; here is an alternative definition for
the loadConfig function he gave. Uses type-classes and liftIO. I find it
easier to use type-classes when dealing with monad transformers, especially
if you have more than a couple of them. You get automatic lifting for every
monad transformer in the stack except IO, for which you need to use liftIO.

Please ask if you have any questions.

loadConfig :: (MonadError MyError m, MonadIO m) => String -> m Config
loadConfig _ = do
  liftIO $ putStrLn "foo"
  throwError ConfigError

HTH,
Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110823/da5e17d9/attachment.htm>


More information about the Beginners mailing list