liveBook · Manning

Put

As explained in Learn Haskell by Example

put is a StateT operation that replaces the current state with a supplied value.

put replaces the current state managed by StateT with a supplied value. Its type is put :: Monad m => s -> StateT s m (), so it works over an underlying monad and returns (). section 15.1.2

Use put alongside the other essential StateT operations:

  • get retrieves the current state. section 15.1.2
  • modify transforms the existing state instead of replacing it outright. section 15.1.2
  • StateT can manage application data such as recursion depth and transferred-file counts while running in IO. section 15.1.2

How Learn Haskell by Example covers it

How deep it goes
Defines put's type and role, then contrasts replacement with get and modify without showing a dedicated put example.
Examples
Uses a file-synchronization application whose StateT state tracks recursion depth and transferred-file counts.
What it assumes
Assumes familiarity with Haskell type signatures and introduces StateT's managed state and underlying monad context.
What you can do after
Apply put to reset or replace state inside a StateT computation.
How it connects
Connects put with StateT, get, modify, Monad, ReaderT, MonadIO, and IO.

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.