The State Monad: A Tutorial for the Confused? - Brandon.Si(mmons)

<![endif] Brandon.Si(mmons) RSS Art Code Misc All About me Oct 24 th , 2009 12:16 am I’ve written this brief tutorial on haskell’s State monad to help bridge some of the elusive gaps that I encountered in other explanations I’ve read, and to try to cut through all the sticky abstraction. This is written for someone who has a good understanding of the Maybe and List monads, but has gotten stuck trying to understand State. I hope it’s helpful! To understand a monad you look at it’s datatype and then at the definition for bind ( >>= ). Most monad tutorials start by showing you the data declaration of a State s a in passing, as if it needed no explanation: 1 newtype State s a = State { runState :: s -> ( a , s ) } But this does need explanation! This is crazy stuff and nothing like what we’ve seen before in the list monad or the Maybe monad: ...

Linked on 2014-12-24 23:40:23 | Similar Links