Copyright | (c) 2017 Harendra Kumar |
---|---|
License | MIT-style |
Maintainer | harendra.kumar@gmail.com |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
Results of the RecorderT
computations are recorded in a running journal
using the record
combinator. A computation can be paused at any point
using the pause
primitive returning a Recording
that can be used to
restart the computation from the same point later. When the recording is
replayed, the record
combinator returns the previously recorded result of
the computation from the journal instead of actually running the
computation again.
import Control.Monad.IO.Class (liftIO) import Control.Monad.Trans.Recorder (runRecorderT, record, pause, Paused(..), blank) import Control.Exception (catch) main = do recording <- (runRecorderT blank computation >> return blank) `catch` \(Paused r) -> return r putStrLn "Computation paused, resuming again with recorded logs" runRecorderT recording computation return () where computation = do x1 <- record $ liftIO $ return 1 record $ liftIO $ print ("A", x1) x2 <- record $ liftIO $ return 2 record pause record $ liftIO $ print ("B", x1, x2)
Note that only those computations are replayed that are explicitly recorded.
Unrecorded impure computations can result in the program misbehaving if it
takes a different path upon replay. Instead of recording selectively you
can enforce recording of each and every operation using the AutoRecorder
module.
- data RecorderT m a
- data Journal
- class Monad m => MonadRecorder m where
- runRecorderT :: Monad m => Recording -> RecorderT m a -> m a
- class Recordable a where
- data Recording
- blank :: Recording
- record :: (Recordable a, Read a, Show a, MonadRecorder m) => m a -> m a
- data Paused = Paused Recording
- pause :: (MonadRecorder m, MonadThrow m) => m ()
Documentation
The monad record and play transformer. Maintains a running log of the results of monadic actions.
MonadTrans RecorderT Source # | |
MonadTransControl RecorderT Source # | |
MonadBase b m => MonadBase b (RecorderT m) Source # | |
MonadBaseControl b m => MonadBaseControl b (RecorderT m) Source # | |
Monad m => Monad (RecorderT m) Source # | |
Functor m => Functor (RecorderT m) Source # | |
Monad m => Applicative (RecorderT m) Source # | |
MonadIO m => MonadIO (RecorderT m) Source # | |
MonadThrow m => MonadThrow (RecorderT m) Source # | |
MonadCatch m => MonadCatch (RecorderT m) Source # | |
MonadMask m => MonadMask (RecorderT m) Source # | |
Monad m => MonadRecorder (RecorderT m) Source # | |
type StT RecorderT a Source # | |
type StM (RecorderT m) a Source # | |
The internal log state kept when recording or replaying.
class Monad m => MonadRecorder m where Source #
A monad with the ability to record and play the results of monadic actions.
getJournal :: m Journal Source #
putJournal :: Journal -> m () Source #
play :: Recording -> m () Source #
Play a previously recorded journal. This function can be used to set a replay journal at any point.
Monad m => MonadRecorder (RecorderT m) Source # | |
class Recordable a where Source #
A type that can be recorded.
(Show a, Read a) => Recordable a Source # | |
The log entries returned when an action is suspend
ed.
record :: (Recordable a, Read a, Show a, MonadRecorder m) => m a -> m a Source #
Add the result of an action to the recording journal. During replay, if the result of an action is available in the replay journal then get it from the journal instead of running the action.
Exception thrown when pause
is called.
pause :: (MonadRecorder m, MonadThrow m) => m () Source #
Pause a computation before completion for resuming later.
Throws Paused
exception which carries the current recorded logs.