[commit: ghc] master: Move reifyGHCi function into GhciMonad type class (3caeb44)
git at git.haskell.org
git at git.haskell.org
Wed Mar 6 21:50:02 UTC 2019
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/3caeb443b2bc2c2ef6f43ce59abfc1cfe3ba579f/ghc
>---------------------------------------------------------------
commit 3caeb443b2bc2c2ef6f43ce59abfc1cfe3ba579f
Author: Zejun Wu <watashi at fb.com>
Date: Mon Jan 21 16:28:01 2019 -0800
Move reifyGHCi function into GhciMonad type class
This was the suggested change in !176 but missed the batch merge (!263).
>---------------------------------------------------------------
3caeb443b2bc2c2ef6f43ce59abfc1cfe3ba579f
ghc/GHCi/UI/Monad.hs | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/ghc/GHCi/UI/Monad.hs b/ghc/GHCi/UI/Monad.hs
index 4287c09..51f1366 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
More information about the ghc-commits
mailing list