Skip to content

Instantly share code, notes, and snippets.

@evancz
Created April 23, 2014 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evancz/11229518 to your computer and use it in GitHub Desktop.
Save evancz/11229518 to your computer and use it in GitHub Desktop.
General purpose library for undo/redo. Inspired by David Nolen's talk at Philly ETE.
module History where
data Step a = Undo | Redo | Checkpoint a | NoCheckpoint a
foldp : (a -> b -> b) -> b -> Signal (Step a) -> Signal b
-- It could also be interesting to have custom strategies for keeping track
-- of history. Maybe you want to have a fixed size stack, infinite stack,
-- stack with exponential decay, etc.
foldpWith : History b -> (a -> b -> b) -> b -> Signal (Step a) -> Signal b
type History a =
{ undo : History a -> History a
, redo : History a -> History a
, add : a -> History a -> History a
}
finite : Int -> History a
finite n =
{ undo = ...
, redo = ...
, add = ...
}
infinite : History a
exponentialDecay : [(Int,Fidelity)] -> History a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment