[Haskell-cafe] Help!! Cannot get RandT and liftIO to work together...

JP Moresmau jpmoresmau at gmail.com
Thu Dec 23 15:52:40 CET 2010


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:
MonadIO<http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Control-Monad-IO-Class.html#t:MonadIO>
m
=> MonadIO<http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Control-Monad-IO-Class.html#t:MonadIO>
 (RandT<http://hackage.haskell.org/packages/archive/MonadRandom/0.1.6/doc/html/Control-Monad-Random.html#t:RandT>
g
m)

And the MonadIO docs say:
Instances:
MonadIO<http://hackage.haskell.org/packages/archive/transformers/0.2.2.0/doc/html/Control-Monad-IO-Class.html#t:MonadIO>
 IO<http://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/System-IO.html#t: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/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20101223/cfcb2bdf/attachment.htm>


More information about the Haskell-Cafe mailing list