From e345c92edb4a2b2f60a9b0adaa68fff76f0d0c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Tue, 12 Aug 2014 18:09:31 +0200 Subject: [PATCH] Make GhcModT's MonadState instance pass through ..to the underlying monad --- Language/Haskell/GhcMod/Monad.hs | 29 +++++++++++++++++++---------- Language/Haskell/GhcMod/Target.hs | 2 +- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Language/Haskell/GhcMod/Monad.hs b/Language/Haskell/GhcMod/Monad.hs index 44e9dd0..6df8380 100644 --- a/Language/Haskell/GhcMod/Monad.hs +++ b/Language/Haskell/GhcMod/Monad.hs @@ -30,8 +30,6 @@ module Language.Haskell.GhcMod.Monad ( , withOptions -- ** Exporting convenient modules , module Control.Monad.Reader.Class - , module Control.Monad.Writer.Class - , module Control.Monad.State.Class , module Control.Monad.Journal.Class ) where @@ -85,10 +83,10 @@ import Control.Monad.Trans.Control (MonadBaseControl(..), StM, liftBaseWith, import Control.Monad.Trans.Class import Control.Monad.Reader.Class -import Control.Monad.Writer.Class -import Control.Monad.State.Class +import Control.Monad.Writer.Class (MonadWriter) +import Control.Monad.State.Class (MonadState(..)) -import Control.Monad.Error (Error(..), MonadError, ErrorT, runErrorT) +import Control.Monad.Error (MonadError, ErrorT, runErrorT) import Control.Monad.Reader (ReaderT, runReaderT) import Control.Monad.State.Strict (StateT, runStateT) import Control.Monad.Trans.Journal (JournalT, runJournalT) @@ -155,13 +153,18 @@ newtype GhcModT m a = GhcModT { #endif , MonadReader GhcModEnv , MonadWriter w - , MonadState GhcModState , MonadError GhcModError ) instance MonadTrans GhcModT where lift = GhcModT . lift . lift . lift . lift +instance MonadState s m => MonadState s (GhcModT m) where + get = GhcModT $ lift $ lift $ lift $ get + put = GhcModT . lift . lift . lift . put + state = GhcModT . lift . lift . lift . state + + #if MONADIO_INSTANCES instance MonadIO m => MonadIO (StateT s m) where liftIO = lift . liftIO @@ -283,17 +286,23 @@ toGhcModT a = do ---------------------------------------------------------------- +gmsGet :: IOish m => GhcModT m GhcModState +gmsGet = GhcModT get + +gmsPut :: IOish m => GhcModState -> GhcModT m () +gmsPut = GhcModT . put + options :: IOish m => GhcModT m Options options = gmOptions <$> ask cradle :: IOish m => GhcModT m Cradle cradle = gmCradle <$> ask -getCompilerMode :: (Functor m, MonadState GhcModState m) => m CompilerMode -getCompilerMode = gmCompilerMode <$> get +getCompilerMode :: IOish m => GhcModT m CompilerMode +getCompilerMode = gmCompilerMode <$> gmsGet -setCompilerMode :: MonadState GhcModState m => CompilerMode -> m () -setCompilerMode mode = (\s -> put s { gmCompilerMode = mode } ) =<< get +setCompilerMode :: IOish m => CompilerMode -> GhcModT m () +setCompilerMode mode = (\s -> gmsPut s { gmCompilerMode = mode } ) =<< gmsGet ---------------------------------------------------------------- diff --git a/Language/Haskell/GhcMod/Target.hs b/Language/Haskell/GhcMod/Target.hs index 572388b..1744a72 100644 --- a/Language/Haskell/GhcMod/Target.hs +++ b/Language/Haskell/GhcMod/Target.hs @@ -15,7 +15,7 @@ setTargetFiles :: IOish m => [FilePath] -> GhcModT m () setTargetFiles files = do targets <- forM files $ \file -> G.guessTarget file Nothing G.setTargets targets - mode <- gmCompilerMode <$> get + mode <- getCompilerMode if mode == Intelligent then loadTargets Intelligent else do