Comment by eru
9 years ago
If you use persistent data structures in your implementation (like would be the default in Haskell), your data structures themselves don't need to know about undo/redo. Just keep references to the old state around (in an undo tree or a linear structure for simplicity), and just switch back to them if necessary. Don't explicitly manipulate your data structures. Sharing will take care of keeping the overheads low.
> Don't explicitly manipulate your data structures. Sharing will take care of keeping the overheads low.
Immutability is one of the strong points of Piece Tables.
Don't forget that this is the most simple implementation of a Piece Table. If you are in any way concerned about performance, you can quite easily implement caching, sharing, etc.
I suspect we are in violent agreement. I was just taking aim at
> [...] "undo" is done by swapping the last left Leaf with an empty Leaf. Redo is done by rotating the last left node's leaves.
Which is more complicated than you need to be in an immutable setting to implement undo/redo.