+setGHCiState s = GHCi $ \r -> liftIO $ writeIORef r s
+
+liftGhc :: Ghc a -> GHCi a
+liftGhc m = GHCi $ \_ -> m
+
+instance MonadIO GHCi where
+ liftIO m = liftGhc $ liftIO m
+
+instance GhcMonad GHCi where
+ setSession s' = liftGhc $ setSession s'
+ getSession = liftGhc $ getSession
+
+instance ExceptionMonad GHCi where
+ gcatch m h = GHCi $ \r -> unGHCi m r `gcatch` (\e -> unGHCi (h e) r)
+ gbracket acq rel ib =
+ GHCi $ \r -> gbracket (unGHCi acq r)
+ (\x -> unGHCi (rel x) r)
+ (\x -> unGHCi (ib x) r)
+ gfinally th cu =
+ GHCi $ \r -> gfinally (unGHCi th r) (unGHCi cu r)
+
+instance WarnLogMonad GHCi where
+ setWarnings warns = liftGhc $ setWarnings warns
+ getWarnings = liftGhc $ getWarnings