In part I of this blog series I showed a simple InfinityMonad, which allows to treat special calculations as infinity. This time I want to demonstrate a ported version of the UndoMonad (see the Haskell version). This monad defines an environment which allows you to undo and redo state changes. You probably know this behavior from your favorite text editor.
Let’s start by using this monad in a small sample:
The definition of this monad is easy if we use the StateMonad, which is already implemented in the FSharp.Monad project (you get the bits from nuget.org). We only need to define the kind of state which should be passed through the monad.
Now we need some helpers, which allow to access and manipulate our history.
In the next part I’ll show a DistributionMonad, which allows to perform queries to probability scenarios.
Tags: F#, monad
Say I wanted to use this as part of a UI. Could you extend the example to show how state changes and undo redo could be processed asynchronously via events or observables.
Comment by Brad Phelan — Saturday, 13. April 2013 um 17:18 Uhr