Skip to content

Chapter 31: State

31.1 State Machine

Turnstile Example

Basic Model in Haskell

Sequencing Steps

31.2 Introducing State

newtype

Where did the State constructor go?

Instantiating the Monad

Understanding the Bind Operator

31.3 Turnstile using State

Using the Turnstile State monad

evalState and execState

Setting the State

Accessing the State

Monadic Control Structures

31.4 Pseudo-Random Numbers

Haskell Global Pseudo-Random Number Generator

Haskell Pseudo-Random Number Generator with Explicit State

Example: Rolling Dice

Dice with State

State is also a Functor and an Applicative

Pseudo-random values of different types

(Probably) don't put or get

Better Random Numbers

31.5 Handling Combined States

State-Processing a Subcomponent

Generic Subcomponent Processing

31.6 Notes