<div dir="ltr">Hi haskell-beginners,<div><br></div><div>I&#39;m starting to come to the idea of exposing a Monad as a means of controlling an API.  So, I&#39;ve started creating my own Monad data types based on classical monads.  However, I&#39;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 =&gt; 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 -&gt; Example m p</div><div style>  -- a :: Example m o </div><div style>  a &gt;&gt;= f = ...</div><div style><br></div><div style>My intuition tells me that this should be simple, I should just use the State&#39;s bind operation, but I can&#39;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>