reset password
Author Message
rabbott
Posts: 1649
Posted 09:48 Nov 01, 2016 |

The History module has been updated to be a bit more generic. (The underlying strategy for keeping track of history and doing undo and redo is unchanged. It's still just two stacks.)

The following says that History works on any type. (a is a type variable.)

data History a = History { historyStack :: [a], redoStack :: [a] }

We can also generalize the Move type.

type Move a = a -> a

There are three generic History-level operations (notice no initial "h":

makeMove :: Move a -> History a -> History a
redo :: History a -> History a
undo :: History a -> History a

To play TicTacToe with History use tttStart, tttNext, tttPlay, etc. (See the code for the list of operations.) Game has been replaced everywhere by TTT in both files to make it clear that TTT is a specific game.

Last edited by rabbott at 12:56 Nov 01, 2016.