{"id":1074,"date":"2011-08-15T16:42:13","date_gmt":"2011-08-15T16:42:13","guid":{"rendered":"http:\/\/www.navision-blog.de\/2011\/08\/15\/some-special-monads-in-f-part-2-of-n-undomonad\/"},"modified":"2011-08-15T18:47:42","modified_gmt":"2011-08-15T18:47:42","slug":"some-special-monads-in-f-part-2-of-n-undomonad","status":"publish","type":"post","link":"http:\/\/www.navision-blog.de\/blog\/2011\/08\/15\/some-special-monads-in-f-part-2-of-n-undomonad\/","title":{"rendered":"Some special monads in F# &#8211; Part 2 of n &ndash; UndoMonad"},"content":{"rendered":"<p>In <a href=\"http:\/\/www.navision-blog.de\/2011\/08\/15\/some-special-monads-in-f-part-1-of-n-infinitymonad\/\">part I of this blog series<\/a> 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 <a href=\"http:\/\/haskell.org\/haskellwiki\/New_monads\/MonadUndo\">Haskell version<\/a>). This monad defines an environment which allows you to undo and redo state changes. You probably know this behavior from your favorite text editor. <\/p>\n<p>Let\u2019s start by using this monad in a small sample:<\/p>\n<p> <script src=\"https:\/\/gist.github.com\/1147108.js\"> <\/script>  <\/p>\n<p>The definition of this monad is easy if we use the <a href=\"http:\/\/www.navision-blog.de\/2009\/10\/23\/using-monads-in-fsharp-part-i-the-state-monad\/\">StateMonad<\/a>, which is already implemented in the <a href=\"https:\/\/github.com\/panesofglass\/FSharp.Monad\">FSharp.Monad<\/a> project (you get the bits from <a href=\"http:\/\/nuget.org\/List\/Packages\/FSharp.Monad\">nuget.org<\/a>). We only need to define the kind of state which should be passed through the monad.<\/p>\n<p> <script src=\"https:\/\/gist.github.com\/1147146.js\"> <\/script>  <\/p>\n<p>Now we need some helpers, which allow to access and manipulate our history.<\/p>\n<p> <script src=\"https:\/\/gist.github.com\/1147157.js\"> <\/script>  <\/p>\n<p>In the <a href=\"http:\/\/www.navision-blog.de\/2011\/08\/15\/some-special-monads-in-f-part-3-of-n-distributionmonad\/\">next part<\/a> I\u2019ll show a DistributionMonad, which allows to perform queries to probability scenarios.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[448,8],"tags":[664,582],"_links":{"self":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/1074"}],"collection":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/comments?post=1074"}],"version-history":[{"count":3,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/1074\/revisions"}],"predecessor-version":[{"id":1082,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/posts\/1074\/revisions\/1082"}],"wp:attachment":[{"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/media?parent=1074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/categories?post=1074"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.navision-blog.de\/blog\/wp-json\/wp\/v2\/tags?post=1074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}