[Haskell-beginners] Effective use of nested Monads

David Hinkes david.hinkes at gmail.com
Sun Feb 10 23:53:18 CET 2013


Hi haskell-beginners,

I'm starting to come to the idea of exposing a Monad as a means of
controlling an API.  So, I've started creating my own Monad data types
based on classical monads.  However, I'm running into a problem regarding
creating monad definitions when using nested Monads.

For example:

newtype Example m o = Example {
  runExample :: State Int (m o)
}

Is there a clean way to make Example a monad?

instance Monad m => Monad (Example m) where

  -- return is easy
  return = Example . return . return

  -- bind is hard.
  -- f :: o -> Example m p
  -- a :: Example m o
  a >>= f = ...

My intuition tells me that this should be simple, I should just use the
State's bind operation, but I can't seem to make it work.

Any advise would be great.


Thanks, Dave

-- 
David Hinkes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130210/9e66d97e/attachment.htm>


More information about the Beginners mailing list