liveBook · Manning

Lifting

As explained in Functional Design and Architecture: Examples in Haskell

lift is a monad-transformer operation that embeds an action from an underlying monad into a transformed monad.

Lifting embeds an action from an underlying monad into the surrounding transformed monad. In a StateT Board IO stack, lift adapts IO actions so they can run inside StateT. section 7.2.3

Minesweeper board actions

A revealCell action reads and updates the board with get and put, while lifting putStrLn prints status messages. The resulting type is lift :: IO a -> StateT Board IO a. section 7.2.3

Long stacks demonstrate the technique, but combining state into one StateT may offer greater simplicity, convenience, and clarity. section 7.2.3

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Demonstrates single and double lifting with typed Minesweeper and ship-control stacks, while deferring implementation internals.
Examples
Uses Minesweeper board updates, nested score and board state, and spaceship rotation scripts.
What it assumes
Assumes familiarity with Haskell monads, do-notation, StateT, get, put, and monad-stack types.
What you can do after
Build it from scratch by embedding underlying actions and running them through layered StateT computations.
How it connects
Connects monad transformers, StateT, IO, state monads, do-notation, and Free monads.

Also explained in

Compare how 2 books explain lifting →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.