Hedi-0.1: Line oriented editor

Undo

Description

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

Synopsis

Documentation

data History s Source

State stacks wrapping states in time

Constructors

History 

Fields

current :: s

last state putted

undos :: [s]

the history of putted states (reversed) without the redos

redos :: [s]

history of the undo

Instances

Show s => Show (History s) 

type HStateT s m = StateT (History s) mSource

a state monad transformer with the state history

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

facility to write signatures context

Instances

(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

Constructors

UndoT (HStateT s m a) 

Instances

Monad m => MonadState s (UndoT s m)

the MonadState instance for the wrapper

MonadTrans (UndoT s) 
Monad m => Monad (UndoT s m) 
Monad m => Functor (UndoT s m) 
MonadIO m => MonadIO (UndoT s m) 

undoSource

Arguments

:: HCtx m s 
=> UndoT s m Bool

False if the undo stack was empty

tries to get back one step the state

redoSource

Arguments

:: HCtx m s 
=> UndoT s m Bool

False if the redo stack was empty

tries to get back the undo operation

hputSource

Arguments

:: HCtx m s 
=> s

the new state to put

-> UndoT s m ()

monading

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

blank :: s -> History sSource

an History of one state

evalUndoTSource

Arguments

:: Monad m 
=> UndoT s m a

a UndoT action

-> s

the initial state

-> m a

the result

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

execUndoTSource

Arguments

:: Monad m 
=> UndoT s m a

a UndoT action

-> s

the initial state

-> m s

the final state

run the UndoT monad transformer spitting out the final state in the inner monad