Rash thoughts about .NET, C#, F# and Dynamics NAV.

"Every solution will only lead to new problems."

Monday, 15. August 2011

Some special monads in F# – Part 2 of n – UndoMonad

Filed under: F#,Informatik — Steffen Forkmann at 16:42 Uhr

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: ,

1 Comment »

  1. 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

RSS feed for comments on this post. | TrackBack URI

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> .