acme-timemachine- An easy way to perform and unperform IO and other stateful actions.

Safe HaskellNone




data Suspension s Source

Data representing the entire history of the state.

data Universe Source

State of the universe.


type TimeMachine = Undoable Universe Source

Undo-able side-effectful computation monad. Lets you perform and unperform (with undo) computations with side-effects, for example:

main = runTM $ do
    liftIO $ putStrLn "Launching the missiles!"

You can also use suspend and resume for a finer control over execution and unexecution:

main = runTM $ do
    universe <- suspend
    liftIO $ putStrLn "Launching the missiles!"
    resume universe

Beware! You may accidentally create temporal paradoxes such as:

main = runTM $ do
    universe <- suspend
    l <- liftIO $ getLine
    putStrLn l
    unless (null l) $ resume universe

undo :: Undoable s () Source

Rollback the latest addition to the computation's history.

suspend :: Undoable s (Suspension s) Source

Save the history of a computation, to be later loaded with resume.

resume :: Suspension s -> Undoable s () Source

Load the history of a computation, saved by suspend.

runTM :: TimeMachine a -> IO a Source

Execute an undo-able computation.

event :: Undoable s a -> Undoable s a Source

Treat the events occuring inside this block as a single event, that can be undone with a sinle undo invocation. | This will always add exactly one item to the computation's history, even if the block doesn't add any, or even removes some.