[Haskell-cafe] Nested Monads Questions

Chris Kuklewicz haskell at list.mightyreason.com
Sat Aug 12 05:07:01 EDT 2006

Bulat Ziganshin wrote:
> Hello Chris,
> Saturday, August 12, 2006, 4:05:44 AM, you wrote:
>> Nine Base Monads:
>>    IO STM ST ST.Lazy GenParser [] Maybe Either (->)
>> Seven MonadTrans:
>>    ListT ContT ErrorT ReaderT StateT WriterT RWST
> i'm not sure, but isn't Id monad also required for completeness?

Yes, Identity is required for completeness.  And I have added to 
http://haskell.org/haskellwiki/NewMonads#MonadBase this definition:

> -- One can recover MonadIO and liftIO from MonadBase
> class (MonadBase IO m) => MonadIO' m where
>   liftIO' :: IO a -> m a
>   liftIO' = liftBase

Of course, the above is unneeded since you can always write liftBase instead of 

> at least it's included in MonadLib by Iavor S. Diatchki:
> http://www.csee.ogi.edu/~diatchki/monadLib/monadLib-2.0.tar.gz

Hah...I knew someone else had done this.  Also, there is 2.0.1 version of 
monadLib at http://www.cse.ogi.edu/~diatchki/monadLib/

His version is called BaseM, and uses a fundep:

> -- | Provides means to execute a computation in the base of a tower of monads.
> class (Monad m, Monad b) => BaseM m b | m -> b where
>   inBase           :: b a -> m a
> instance BaseM IO IO        where inBase x = x
> instance BaseM [] []        where inBase x = x
> instance BaseM Maybe Maybe  where inBase x = x

I am not sure I like the "inBase" name.  I think "fromBase" might be a better 
match to its type.  The "inBase" seems more like "toBase" which is backwards.

My small test did not need the fundep, and I wonder if there is some creative 
example that shows either that the fundep is useful or a counter example that 
shows something very very clever that would otherwise violate the fundep.

I *might* be able to imagine a transformer stack that pretends to have different 
base monads.

> am i correctly understand that your module is update on Monad
> transformers lib already included in GHC?

Essentially, that is exactly what it is.  It completely replaces MonadIO.


More information about the Haskell-Cafe mailing list