Skip to content

Instantly share code, notes, and snippets.

@evancz
Last active November 23, 2015 20:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evancz/11229888 to your computer and use it in GitHub Desktop.
Save evancz/11229888 to your computer and use it in GitHub Desktop.
module History where
type History state value =
{ state | undo : History s a -> Maybe (History s a)
, redo : History s a -> Maybe (History s a)
, add : a -> History s a -> History s a
, value : History s a -> Maybe a
}
type Infinite a = { past : [a], future : [a] }
infinite : History (Infinite a) a
infinite =
{ past = []
, future = []
, undo h =
case h.past of
[] -> Nothing
x::xs -> Just { h | past <- xs, future <- x :: h.future }
, redo h =
case h.future of
[] -> Nothing
x::xs -> Just { h | past <- x :: h.past, future <- xs }
, add x h =
{ h | past <- x :: h.past, future <- [] }
, value h =
case h.past of
x::_ -> Just x
[] -> Nothing
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment