Saturday, December 01, 2012

Introduction to state monads

I went to my first Zurich FSharp meeting the other day and made a presentation on how to program with state monads in F#.

The presentation is designed to pull you off the ground, to a higher order programming style, using the state and maybe monad as stepping stones. It finishes with stateful lifting.

Here is a link to a slightly improved version: youtube .

Link to sources are below but I would recommend that if you really do not know this type of programming and want to learn, then you should type it back in and allow yourself some creative liberty. This is usually a much better way to learn, than to just copy code!

You can watch it here if you want:


Ville Nurmi said...

I want to say thanks for your presentation. I read the PDF, watched the video and worked on the code for several hours, typing it "in my own words" and trying out alternative ways. After all this I feel that I am finally comfortable enough with monads in order to use them in my own code.

I'm quite new to functional programming and I've been learning about monads for a while from various sources. What was really helpful in your presentation was how you built your way to the monad starting from simple imperative code. Also lifting the state monad to apply to a part of a complex structure was exactly what I wanted to know about practical use of the state monad.

So thanks once again, this has been really helpful!

James Litsios said...

Thank Ville,
Giving that presentation was a little bit like making an airplane take off, and just let it go higher and higher, and although I could see that I lost some of public, it was still a very exciting thing to do. Finishing with the lifting felt a little bit like overdoing it, but I have seen so many monadic state example never get past a "flatworld" view of state. I really wanted to to leave my audience with the path to go past that "limited" view.

Thanks again, comments like that are always a pleasure!

Anonymous said...

I have been struggling with Monads in both Scala and F# for the past year. This well thought out presentation turned the light on for me at last, so a very big thank you.



Unknown said...


I have just come across your talk on YouTube. It’s difficult to explain Monads/Computational Expressions but you have done the best job I have watched or read so far. Your approach of building up to Monads from standard code was a good approach. I am surprised with all the books coming out on F# there are none that just cover computational expressions.