O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The state transformer that we defined is a pretty powerful construct. It lets us use another monad in the context of State Monad. Implementation may look a little hard to get the first time. However, if you remember that all the actions are performed in the internal monad (whatever it might be). To do this, we took advantage of the do.. syntax for the monad (and that it is a Functor and an Applicative instance). All the internal monadic actions are modified from m a  to  m (a, s) and that is how we are able to achieve embedding of a monad inside a state transformer. All monad transformers follow a similar strategy. 

In the mtl implementation of state transformer, you will see two implementations, lazy and strict. In the strict ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required