[Haskell-beginners] Trouble with liftIO in ReaderT

John Smith voldermort at hotmail.com
Sun Jan 30 20:16:43 CET 2011


On 30/01/2011 16:43, Daniel Fischer wrote:
> On Sunday 30 January 2011 15:16:36, John Smith wrote:
>> I'm trying to attach a handler to a Gtk2Hs event, and get the error:
>>
>> No instance for (Control.Monad.IO.Class.MonadIO
>>                      (mtl-1.1.0.2:Control.Monad.Reader.ReaderT
>> (GHC.Ptr.Ptr EAny) IO)) arising from a use of `liftIO'
>> Possible fix:
>>     add an instance declaration for
>>     (Control.Monad.IO.Class.MonadIO
>>        (mtl-1.1.0.2:Control.Monad.Reader.ReaderT (GHC.Ptr.Ptr EAny) IO))
>>
>> This occurs with the sample at
>> http://www.haskell.org/haskellwiki/Gtk2Hs/Tutorials/Intro
>>
>> import Graphics.UI.Gtk
>> import Control.Monad.Trans(liftIO)
>>
>> main = do
>>     initGUI
>>     window<- windowNew
>>     window `on` deleteEvent $ liftIO mainQuit>>  return False
>>     -- i.e., on window deleteEvent (liftIO mainQuit>>  return False)
>>     widgetShow window
>>     mainGUI
>>
>> Why can't GHC find the instance MonadIO m =>  MonadIO (ReaderT r m)?
>>
>
> GHC specifies the package the offending ReaderT comes from, mtl-1.1.0.2.
> mtl-1.1.0.2's ReaderT is an instance of mtl-1.1.0.2's MonadIO class. That
> class was defined in Control.Monad.Trans.
>
> Note that
> a) the package from which the MonadIO class in the error message comes is
> not specified,
> b) it is qualified as Control.Monad.IO.Class.MonadIO, it comes from a
> module of the transformers package.
>
> I suspect that your programme uses inconsistent dependencies, some part of
> it was built against mtl-1.1.0.2, some other part uses mtl-2.* (which is a
> wrapper around transformers, exporting mtl's old API [with a few
> differences]) or transformers directly.
>
> Check which mtl-version gtk2hs was built against (
> $ ghc-pkg describe gtk
> , look at the depends field fairly low down), probably that was built
> against mtl-1.1.0.2.
>
> To fix it you can
> - maybe rebuild gtk2hs (gtk, glade, pango, ...) against mtl-2 [much
> compiling, may not work, but would save some headaches later if it does]
> - build your programme against mtl-1.1.0.2 (either by writing a .cabal file
> specifying mtl-1 or by passing -package mtl-1.1.0.2 on the command line).
>
> HTH,
> Daniel

I had mtl-1 as a system package, and mtl-2 as a user package. I forced the removal of mtl-1, reinstalled gtk (and a few 
other things), and it's working now.

Thank you.




More information about the Beginners mailing list