[commit: haskeline] master: #117: Implement mapInputT. (8da2956)
Ian Lynagh
igloo at earth.li
Mon May 7 13:53:25 CEST 2012
Repository : ssh://darcs.haskell.org//srv/darcs/packages/haskeline
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/8da29568eca603b174b9bc53a65da53387b3392a
>---------------------------------------------------------------
commit 8da29568eca603b174b9bc53a65da53387b3392a
Author: Judah Jacobson <judah.jacobson at gmail.com>
Date: Fri Mar 23 16:54:47 2012 +0000
#117: Implement mapInputT.
>---------------------------------------------------------------
System/Console/Haskeline.hs | 1 +
System/Console/Haskeline/InputT.hs | 5 +++++
System/Console/Haskeline/Monads.hs | 5 +++++
3 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/System/Console/Haskeline.hs b/System/Console/Haskeline.hs
index 715b382..bc5db8f 100644
--- a/System/Console/Haskeline.hs
+++ b/System/Console/Haskeline.hs
@@ -32,6 +32,7 @@ module System.Console.Haskeline(
InputT,
runInputT,
haveTerminalUI,
+ mapInputT,
-- ** Behaviors
Behavior,
runInputTBehavior,
diff --git a/System/Console/Haskeline/InputT.hs b/System/Console/Haskeline/InputT.hs
index 9129a91..fba5705 100644
--- a/System/Console/Haskeline/InputT.hs
+++ b/System/Console/Haskeline/InputT.hs
@@ -150,6 +150,11 @@ execInputT prefs settings run (InputT f)
$ runHistoryFromFile (historyFile settings) (maxHistorySize prefs)
$ runReaderT f run
+-- | Map a user interaction by modifying the base monad computation.
+mapInputT :: (forall b . m b -> m b) -> InputT m a -> InputT m a
+mapInputT f = InputT . mapReaderT (mapStateT (mapStateT
+ (mapReaderT (mapReaderT f))))
+ . unInputT
-- | Read input from 'stdin'.
-- Use terminal-style interaction if 'stdin' is connected to
diff --git a/System/Console/Haskeline/Monads.hs b/System/Console/Haskeline/Monads.hs
index 75de7c2..9dd4aa1 100644
--- a/System/Console/Haskeline/Monads.hs
+++ b/System/Console/Haskeline/Monads.hs
@@ -3,10 +3,12 @@ module System.Console.Haskeline.Monads(
module System.Console.Haskeline.MonadException,
ReaderT(..),
runReaderT',
+ mapReaderT,
asks,
StateT,
runStateT,
evalStateT',
+ mapStateT,
gets,
modify,
update,
@@ -75,6 +77,9 @@ instance MonadTrans (StateT s) where
instance MonadIO m => MonadIO (StateT s m) where
liftIO = lift . liftIO
+mapStateT :: (forall b . m b -> n b) -> StateT s m a -> StateT s n a
+mapStateT f (StateT m) = StateT (\s -> f (m s))
+
runStateT :: Monad m => StateT s m a -> s -> m (a, s)
runStateT f s = do
useXS <- getStateTFunc f s
More information about the Cvs-libraries
mailing list