<div dir="ltr">Hi haskell-beginners,<div><br></div><div>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.</div>
<div><br></div><div>For example:</div><div><br></div><div>newtype Example m o = Example {</div><div style> runExample :: State Int (m o)</div><div style>}</div><div style><br></div><div style>Is there a clean way to make Example a monad?</div>
<div style><br></div><div style>instance Monad m => Monad (Example m) where</div><div style><br></div><div style> -- return is easy</div><div style> return = Example . return . return</div><div style><br></div><div style>
-- bind is hard.</div><div style> -- f :: o -> Example m p</div><div style> -- a :: Example m o </div><div style> a >>= f = ...</div><div style><br></div><div style>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.</div>
<div style><br></div><div style>Any advise would be great.</div><div style><br></div><div style><br></div><div style>Thanks, Dave</div><div style><br></div><div>-- <br>David Hinkes
</div></div>