nix-playgraound/notes/040-haskell-transformer-stack.md

64 lines
1.4 KiB
Markdown
Raw Normal View History

# Haskell Transformer Stacks
This note covers `37-haskell-transformer-stack/`, which composes `ReaderT`, `ExceptT`, and `Writer` in one rollout workflow.
---
## 1. Why a Stack Helps Here
The rollout workflow needs three independent capabilities:
- configuration from an environment,
- explicit business failures, and
- ordered audit output.
This example puts them together directly:
```haskell
type App = ReaderT Env (ExceptT RolloutError (Writer [String]))
```
That is the core teaching point. The effect requirements live in one concrete stack, while the workflow stays readable.
---
## 2. What the Workflow Actually Does
The stack is not there for decoration. The rollout code:
- reads cluster and policy settings,
- rejects restricted or oversized production rollouts, and
- records each successful step in an audit log.
That gives each transformer a concrete job.
---
## 3. Why This Complements the Earlier Examples
Earlier notes introduced these pieces separately:
- `ReaderT` and `Except` in `10-haskell-effects/`, and
- `Writer` in `31-haskell-writer-audit/`.
This example shows the next practical step: combining them when one workflow needs all three.
---
## 4. Commands to Try
```bash
cd 37-haskell-transformer-stack
nix develop
cabal run
cabal run -- api:production:4
cabal test
nix build
./result/bin/mini-stack api:production:4
nix run . -- api:production:4
nix flake check
```