Effects for Haskells
Effects in Haskell are how a pure language still reads files, prints output and keeps state. The IO type marks actions that touch the outside world, and they run only from main. Mutable state is modelled with the State monad, IORef or STRef, keeping the impure parts visible in type signatures.
Stage: Abstractions · Part of the Haskell roadmap · Last reviewed 19 November 2026
What to learn in Effects
- Read input and print output using IO actions inside do blocks
- Separate pure logic from IO code to make testing easier
- Thread state through a computation with the State monad
- Use IORef for a mutable counter and explain when ST is better
- Handle exceptions in IO with catch or try
Effects interview questions
Why does Haskell use the IO type?
IO marks values that describe actions with side effects. A function returning IO String is not a string but a recipe that produces one when run. This keeps pure code free of hidden effects and makes the effectful boundary obvious in types.
What is the difference between the State monad and IORef?
State threads a value through a pure computation, so the function stays referentially transparent and easy to test. IORef is a real mutable cell that lives in IO. Use State when you can, and IORef when you need shared mutable data.
Where Effects fits in the Haskell roadmap
Effects belongs to the Abstractions stage (advanced level). The functional toolkit.
Other units in this stage
Back to the full Haskell roadmap