monad-recorder

Record and replay the results of monadic actions http://github.com/harendra-kumar/monad-recorder

Version on this page:0.1.1
LTS Haskell 12.22:0.1.1
Stackage Nightly 2018-09-28:0.1.1
Latest on Hackage:0.1.1

See all snapshots monad-recorder appears in

MIT licensed by Harendra Kumar
Maintained by harendra.kumar@gmail.com

Module documentation for 0.1.1

Monad Recorder

A monad transformer that allows recording the results of monadic actions and allows replaying them later so that the application can resume from the same point.

Results of a RecorderT computation 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 being replayed 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)

This package is inspired by the logging implementation in the transient package by Alberto G. Corona. Related packages:

Changes

0.1.1

  • GHC 8.4.1 support

0.1.0

  • Initial release
Used by 1 package:
comments powered byDisqus