I understand the error below, but I'm not really sure what an instance of liftIO would look like for the Identity functor. I guess I'm not all to clear on what an identity functor is.
I'm a little fuzzy on what an identity monad is. I understand that id gives the identity of something back pretty well though. Can anyone help?
If anyone could help me fix the code below as well as explain the questions I have above it would be a great help.
import Control.Monad.Trans.State
import Control.Monad.IO.Class
type MyState = State Int
modAndPrintState :: Int -> MyState ()
modAndPrintState x = do
get >>= \i -> do
liftIO . print $ i
if even x then put (x + i) else put (i * (x + 1) - x)
main = undefined
-- Prelude Control.Monad.Trans.State> :r
-- [1 of 1] Compiling Main ( blah2.hs, interpreted )
-- blah2.hs:9:5:
-- No instance for (MonadIO Data.Functor.Identity.Identity)
-- arising from a use of `liftIO'
-- Possible fix:
-- add an instance declaration for
-- (MonadIO Data.Functor.Identity.Identity)
-- In the first argument of `(.)', namely `liftIO'
-- In the expression: liftIO . print
-- In a stmt of a 'do' block: liftIO . print $ i
-- Failed, modules loaded: none.
Thanks!