liveBook · Manning

State

As explained in Learn Haskell by Example

Program state is the collection of values and conditions describing a computation at a particular point during its execution.

Program state is the data and execution context present at a particular point while a program runs. It includes values such as variables, the system running the program, and its environment; accounting for it makes intended behavior harder to verify. section 1.2

State can be handled in different ways:

  • Object-oriented programming splits state into objects and provides interfaces for controlled access. section 1.2
  • Pure functional programming tries to minimize state rather than divide it into separate packages. section 1.2.1

A cake recipe

An instruction-based recipe changes the kitchen’s state after every step: “mix well” only makes sense when something is available to mix. A more functional description defines a cake batter, combines it with a chocolate mixture, and then defines the baked cake from that result, reducing dependence on hidden intermediate state. section 1.2.1

How Learn Haskell by Example covers it

How deep it goes
Defines state through variables and execution context, then explains its dependencies using a concrete recipe analogy.
Examples
Uses variables, execution environments, and chocolate-cake preparation to make state and state dependencies concrete.
What you can do after
Evaluate how changing data and execution context affect program behavior, and recognize why minimizing state can simplify reasoning.
How it connects
Connects state with object-oriented programming, pure functional programming, and declarative programming.

Also explained in

Compare how 39 books explain state →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.