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

A State Monad is a function that takes a state s and produces an output (as). Here, a is the result of monadic computation, and in all monad steps, the state s is threaded through each step. This is illustrated in the following diagram:

During the monadic bind operations, the result of the previous operation is taken and is fed into a function that produces the next output, as shown in the preceding diagram. 

It is important to note two specific operations that are defined in the context of the State Monad. These operations are get and put, used for getting the current state and saving a new state, respectively. 

In the ...

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