nix-playgraound/notes/012-haskell-effects.md

1.1 KiB

Haskell Effects with ReaderT and Except

This note covers 10-haskell-effects/, which models application logic with an environment, explicit errors, and a small effect stack.


1. What the Stack Represents

The example uses:

  • ReaderT Env for read-only configuration, and
  • Except AppError for failures that belong to the domain.

That is an important intermediate step because it separates three things cleanly:

  • configuration,
  • business logic, and
  • error handling.

2. Why the Functions Use Constraints

The library functions are written against MonadReader Env and MonadError AppError constraints rather than a concrete stack type.

That keeps the functions reusable. They say what capabilities they need, not exactly which monad stack must provide them.

The concrete stack still exists:

type App = ReaderT Env (Except AppError)

But the function signatures stay more flexible and easier to test.


3. Commands to Try

cd 10-haskell-effects

nix develop
cabal run
cabal run -- haskell
cabal test

nix build
./result/bin/mini-effects haskell

nix run . -- haskell
nix flake check