<div>Hello all, sorry I must have taken my stupid pills this morning, I cannot get the following code to compile, what am I missing?</div><div><br></div><div>data MyState=MyState Integer</div><div>newState:: (RandomGen g) => RandT g IO MyState</div>
<div>newState = do</div><div> time<-liftIO getCPUTime</div><div> rand<-getRandomR (1,6)</div><div> return $ MyState (time+rand) </div><div><br></div><div>newStateIO :: IO MyState</div><div>
newStateIO = do</div><div> r<-getStdGen</div><div> evalRandT newState r</div><div><br></div><div>-> Could not deduce (MonadIO (RandT g IO)) from the context (RandomGen g) arising from a use of `liftIO' at ...:4:15-31</div>
<div>Possible fix:</div><div> add (MonadIO (RandT g IO)) to the context of</div><div> the type signature for `newState'</div><div> or add an instance declaration for (MonadIO (RandT g IO))<span class="Apple-tab-span" style="white-space:pre">        </span>Pirates.hs<span class="Apple-tab-span" style="white-space:pre">        </span>/Pirates/src<span class="Apple-tab-span" style="white-space:pre">        </span>line 167<span class="Apple-tab-span" style="white-space:pre">        </span>Problem</div>
<div><br></div><div>But the MonadRandom docs say:</div><div>Instances:</div><div><span class="Apple-style-span" style="font-family: monospace; font-size: 13px; line-height: 16px; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><a href="http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Control-Monad-IO-Class.html#t:MonadIO" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-decoration: none; color: rgb(196, 69, 29); ">MonadIO</a> m => <a href="http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Control-Monad-IO-Class.html#t:MonadIO" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-decoration: none; color: rgb(196, 69, 29); ">MonadIO</a> (<a href="http://hackage.haskell.org/packages/archive/MonadRandom/0.1.6/doc/html/Control-Monad-Random.html#t:RandT" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-decoration: none; color: rgb(196, 69, 29); ">RandT</a> g m)</span></div>
<div><span class="Apple-style-span" style="font-family: monospace; font-size: 13px; line-height: 16px; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><br></span></div>
<div><span class="Apple-style-span" style="font-family: monospace; font-size: 13px; line-height: 16px; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">And the MonadIO docs say:</span></div>
<div><span class="Apple-style-span" style="font-family: monospace; font-size: 13px; line-height: 16px; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">Instances:</span></div>
<div><span class="Apple-style-span" style="font-family: monospace; font-size: 13px; line-height: 16px; white-space: nowrap; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><span class="Apple-style-span" style="font-family: sans-serif; line-height: 18px; white-space: normal; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; "><table style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: inherit; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; ">
<tbody style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><tr style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">
<td class="src" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.2em; padding-right: 0.5em; padding-bottom: 0.2em; padding-left: 0.5em; font-family: monospace; line-height: 16px; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(240, 240, 240); vertical-align: top; white-space: nowrap; background-position: initial initial; background-repeat: initial initial; ">
<a href="http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Control-Monad-IO-Class.html#t:MonadIO" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-decoration: none; color: rgb(196, 69, 29); ">MonadIO</a> <a href="http://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/System-IO.html#t:IO" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; text-decoration: none; color: rgb(196, 69, 29); ">IO</a></td>
</tr></tbody></table></span></span></div><div>So it looks to me it should work!</div><div>I've also tried to replace IO by MonadIO m=> in the signature, or remove all signatures. No joy.</div><div><br></div><div>Thanks for any help. </div>
<br>-- <br>JP Moresmau<br><a href="http://jpmoresmau.blogspot.com/">http://jpmoresmau.blogspot.com/</a><br>