[Haskell-cafe] Combining computations
Felipe Lessa
felipe.lessa at gmail.com
Sun May 3 07:04:44 EDT 2009
I don't know if I understood your intentions, but let's go. The
problem is that you're trying to combine different monads. We
have
mplus :: MonadPlus m => m a -> m a -> m a,
so you never leave 'm', but you want
mplus' :: ??? => n a -> m a -> m a
where 'n' could be a different monad. In some specific cases
where you know the internal structure of the monad, you can write
'mplus'', for example:
mplus' :: MonadPlus m => Maybe a -> m a -> m a
mplus' m l = maybeToMonad m `mplus` l
maybeToMonad :: Monad m => Maybe a -> m a
maybeToMonad = maybe (fail "Nothing") return
In general, however, this operation can't be done. For example,
how would you write:
mplus' :: IO a -> [a] -> [a]
?
HTH,
--
Felipe.
More information about the Haskell-Cafe
mailing list