MIT licensed by Harendra Kumar
Maintained by [email protected]

Module documentation for 0.1.1

This version can be pinned in stack with:[email protected]:492850cf9bba7d944391e2868f955cb8f8d6dbf97046b8ff8b160524d052c378,2378

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