summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorZejun Wu <watashi@fb.com>2019-01-21 16:28:01 -0800
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-03-06 16:11:52 -0500
commit3caeb443b2bc2c2ef6f43ce59abfc1cfe3ba579f (patch)
tree7ea8dd82ee10e6b129c256044aff5de9105c2d0c /ghc
parent78dd04f9126dc5df966070b8db4b39a517a9d99f (diff)
downloadhaskell-3caeb443b2bc2c2ef6f43ce59abfc1cfe3ba579f.tar.gz
Move reifyGHCi function into GhciMonad type class
This was the suggested change in !176 but missed the batch merge (!263).
Diffstat (limited to 'ghc')
-rw-r--r--ghc/GHCi/UI/Monad.hs16
1 files changed, 3 insertions, 13 deletions
diff --git a/ghc/GHCi/UI/Monad.hs b/ghc/GHCi/UI/Monad.hs
index 4287c09b8c..51f13663ea 100644
--- a/ghc/GHCi/UI/Monad.hs
+++ b/ghc/GHCi/UI/Monad.hs
@@ -240,19 +240,6 @@ newtype GHCi a = GHCi { unGHCi :: IORef GHCiState -> Ghc a }
reflectGHCi :: (Session, IORef GHCiState) -> GHCi a -> IO a
reflectGHCi (s, gs) m = unGhc (unGHCi m gs) s
-reifyGHCi :: GhciMonad m => ((Session, IORef GHCiState) -> IO a) -> m a
-reifyGHCi f = do
- s <- GHC.getSession
- sRef <- liftIO $ newIORef s
- gs <- getGHCiState
- gsRef <- liftIO $ newIORef gs
- ret <- liftIO (f (Session sRef, gsRef)) `gfinally` do
- s' <- liftIO $ readIORef sRef
- GHC.setSession s'
- gs' <- liftIO $ readIORef gsRef
- setGHCiState gs'
- return ret
-
startGHCi :: GHCi a -> GHCiState -> Ghc a
startGHCi g state = do ref <- liftIO $ newIORef state; unGHCi g ref
@@ -270,16 +257,19 @@ class GhcMonad m => GhciMonad m where
getGHCiState :: m GHCiState
setGHCiState :: GHCiState -> m ()
modifyGHCiState :: (GHCiState -> GHCiState) -> m ()
+ reifyGHCi :: ((Session, IORef GHCiState) -> IO a) -> m a
instance GhciMonad GHCi where
getGHCiState = GHCi $ \r -> liftIO $ readIORef r
setGHCiState s = GHCi $ \r -> liftIO $ writeIORef r s
modifyGHCiState f = GHCi $ \r -> liftIO $ modifyIORef r f
+ reifyGHCi f = GHCi $ \r -> reifyGhc $ \s -> f (s, r)
instance GhciMonad (InputT GHCi) where
getGHCiState = lift getGHCiState
setGHCiState = lift . setGHCiState
modifyGHCiState = lift . modifyGHCiState
+ reifyGHCi = lift . reifyGHCi
liftGhc :: Ghc a -> GHCi a
liftGhc m = GHCi $ \_ -> m