Last active
November 23, 2015 20:44
-
-
Save evancz/11229888 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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