This code has been taken from http://haskell.org A Monad transformer UndoT on a state supporting undo , redo and hput to push the last state on history. Redo stack is blanked on hput

- data History s = History {}
- type HStateT s m = StateT (History s) m
- class (Monad m, MonadState (History s) (HStateT s m)) => HCtx m s
- newtype Monad m => UndoT s m a = UndoT (HStateT s m a)
- undo :: HCtx m s => UndoT s m Bool
- redo :: HCtx m s => UndoT s m Bool
- hput :: HCtx m s => s -> UndoT s m ()
- blank :: s -> History s
- evalUndoT :: Monad m => UndoT s m a -> s -> m a
- execUndoT :: Monad m => UndoT s m a -> s -> m s

# Documentation

State stacks wrapping states in time

class (Monad m, MonadState (History s) (HStateT s m)) => HCtx m s Source

facility to write signatures context

(Monad m, MonadState (History s) (HStateT s m)) => HCtx m s |

newtype Monad m => UndoT s m a Source

a wrapper around HStateT to derive his classes and add an instance

tries to get back one step the state

tries to get back the undo operation

push the old state in the undo stack and set the new state (alternative to put)

run the UndoT monad transformer spitting out the computation result in the inner monad