monad-recorder: Record and replay the results of monadic actions

[ general, library, mit ] [ Propose Tags ]

A monad transformer and class that allows recording the results of monadic actions and replay them later. Inspired by the logging implementation in the transient package by Alberto G. Corona. Related packages:


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0, 0.1.1
Change log Changelog.md
Dependencies base (>=4.8 && <5), exceptions (>=0.8 && <0.11), monad-control (>=1.0 && <2), mtl (>=2.2 && <3), transformers (>=0.4 && <0.6), transformers-base (>=0.4 && <0.5) [details]
License MIT
Copyright 2017 Harendra Kumar
Author Harendra Kumar
Maintainer harendra.kumar@gmail.com
Category General
Home page http://github.com/harendra-kumar/monad-recorder
Bug tracker https://github.com/harendra-kumar/monad-recorder/issues
Source repo head: git clone https://github.com/harendra-kumar/monad-recorder
Uploaded by harendra at 2018-03-18T20:51:15Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 1467 total (7 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-03-18 [all 1 reports]

Readme for monad-recorder-0.1.1

[back to package description]

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: