Help!! Cannot get RandT and liftIO to work together...

Hello all, sorry I must have taken my stupid pills this morning, I cannot get the following code to compile, what am I missing? data MyState=MyState Integer newState:: (RandomGen g) => RandT g IO MyState newState = do time<-liftIO getCPUTime rand<-getRandomR (1,6) return $ MyState (time+rand) newStateIO :: IO MyState newStateIO = do r<-getStdGen evalRandT newState r -> Could not deduce (MonadIO (RandT g IO)) from the context (RandomGen g) arising from a use of `liftIO' at ...:4:15-31 Possible fix: add (MonadIO (RandT g IO)) to the context of the type signature for `newState' or add an instance declaration for (MonadIO (RandT g IO)) Pirates.hs /Pirates/src line 167 Problem But the MonadRandom docs say: Instances: MonadIOhttp://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Co... m => MonadIOhttp://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Co... (RandThttp://hackage.haskell.org/packages/archive/MonadRandom/0.1.6/doc/html/Contr... g m) And the MonadIO docs say: Instances: MonadIOhttp://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Co... IOhttp://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/System-IO.... So it looks to me it should work! I've also tried to replace IO by MonadIO m=> in the signature, or remove all signatures. No joy. Thanks for any help. -- JP Moresmau http://jpmoresmau.blogspot.com/

GHC 6.12.1, base 4.2.0.0, MonadRandom-0.1.6, transformers-0..2.2.0, on Windows.Could it be that my system is not picking up the MonadIO I think it does? JP On Thu, Dec 23, 2010 at 4:13 PM, Daniel Fischer < daniel.is.fischer@googlemail.com> wrote:
On Thursday 23 December 2010 15:52:40, JP Moresmau wrote:
Hello all, sorry I must have taken my stupid pills this morning, I cannot get the following code to compile, what am I missing?
Works here. Which versions of the packages and GHC are you using?
-- JP Moresmau http://jpmoresmau.blogspot.com/

On Thursday 23 December 2010 16:21:05, JP Moresmau wrote:
GHC 6.12.1, base 4.2.0.0, MonadRandom-0.1.6, transformers-0..2.2.0, on Windows.
Could it be that my system is not picking up the MonadIO I think it does?
Probably. With 6.12.1, you'll probably have an mtl-1.* installed, so the MonadIO used by MonadRandom is not the same as the one provided by transformers. Reinstall mtl to get version 2.* and MonadRandom if that's the case.

Thanks a million, it worked! Following all the dependencies sometimes is a bit of a headache. But in a sense, I'm happy to see I had understood how to use the monad transformer correctly, it wasn't me being (too) stupid. Thanks again! JP On Thu, Dec 23, 2010 at 4:32 PM, Daniel Fischer < daniel.is.fischer@googlemail.com> wrote:
On Thursday 23 December 2010 16:21:05, JP Moresmau wrote:
GHC 6.12.1, base 4.2.0.0, MonadRandom-0.1.6, transformers-0..2.2.0, on Windows.
Could it be that my system is not picking up the MonadIO I think it does?
Probably. With 6.12.1, you'll probably have an mtl-1.* installed, so the MonadIO used by MonadRandom is not the same as the one provided by transformers. Reinstall mtl to get version 2.* and MonadRandom if that's the case.
-- JP Moresmau http://jpmoresmau.blogspot.com/

On Thursday 23 December 2010 15:52:40, JP Moresmau wrote:
what am I missing?
Maybe I just spotted it:
But the MonadRandom docs say: Instances:
MonadIO<http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Co... Monad-IO-Class.html#t:MonadIO> m links to the transformers package, but MonadRandom uses mtl.
=> MonadIO<http://hackage.haskell.org/packages/archive/transformers/0.2.2.0 /doc/html/Control-Monad-IO-Class.html#t:MonadIO>
participants (2)
-
Daniel Fischer
-
JP Moresmau