monad-recorder

Record and replay the results of monadic actions

http://github.com/harendra-kumar/monad-recorder

Version on this page:0.1.0
LTS Haskell 12.26: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 [email protected]
This version can be pinned in stack with:monad-recorder-0.1.0@sha256:469853bb3f4d74ad811674cdb233843060d5ffc376df29532d1233b0c9a7c17d,2308

Module documentation for 0.1.0

Monad Recorder

Build Status Windows Build status Coverage Status

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.0

  • Initial release