Effect Rows vs Row Polymorphism in PureScript Libraries
PureScript library authors must choose between fixed effect rows and row polymorphism when defining functions that interact with effects. This guide compares the two approaches, explains trade-offs, and shows a working example with compilation verification.
30 Aug 2026, 15:45 UTC

PureScript library authors frequently face a choice: expose functions with a concrete effect row, or use row polymorphism to make them effect-agnostic. The decision shapes API stability, compilation speed, and how easily new effects can be added later. Useful takeaway: row polymorphism via forall e. ... lets you write functions that work across effect sets while still requiring callers to handle the effects they use, but it requires disciplined row constraints when composing effects.
Decision and constraints
- Decision: Choose between a fixed effect row in a function's type signature and row polymorphism (
forall e. ...) for modular library design. - Constraints: Target PureScript 0.15+ (earlier versions handle row polymorphism differently), maintain backward-compatible API surface, keep compilation time reasonable for large effect sets, ensure callers are not forced to list effects they don't use.
Compare supported options in a compact table
| Approach | Signature Style | Caller Impact | Adding a New Effect | Compile-Time Overhead | Typical Use Case |
|---|---|---|---|---|---|
| Fixed effect row | Effect row => Type | Callers see the exact effect listed; must handle it or use partial | Changes the function's type; all callers need signature updates | Low; rows are monomorphic | Small, stable APIs where effect set is unlikely to change |
| Row polymorphism | forall e. Effect e => Type | Callers infer the effect set; can be constrained with row constraints | Does not change the polymorphic type; callers may need effect-row constraints added | Moderate; polymorphism adds inference work but scales with effect set size | Libraries targeting diverse effect compositions or plugin-style extensions |
Explain trade-offs
Fixed rows are straightforward: the compiler tracks exactly which effects a function uses, and any deviation produces a clear error. However, adding a single new effect ripples through the entire call chain, forcing signature changes across modules. This can become a maintenance burden in larger codebases.
Row polymorphism decouples the function's type from a concrete effect set. A function declared with forall e. Effect e => ... can be called with any effect that satisfies the constraint. When a new effect is needed, the function signature stays the same, and callers only need to ensure the new effect is handled where the function is invoked. The trade-off is that row inference can be subtle: missing a constraint or misordering row variables may lead to unexpected unresolved effect warnings at call sites. Compilation time grows with the number of row variables in scope, but remains acceptable for typical library sizes.
Concrete implementation and validation
Fixed effect row example
Effect row => String -> Eff row UnitRow polymorphism example
forall e. Effect e => String -> Eff e UnitWhere to run: In a PureScript project directory, execute psc (the PureScript compiler) to check compilation. Required permissions: read access to source files; write access if modifying sources. Meaningful placeholders: $(PROJECT_DIR)/src/Log.purs for the source file, EFFECT_ROW for the effect row variable. Expected checks: psc exits with code 0, no unresolved effect warnings appear in the output. Relevant risks: Adding a new capability to the effect row without updating the row constraint may cause the compiler to emit an error at the call site, or in older PureScript versions produce an ambiguous row variable error. To verify the result, compile the module with psc --output=output.js src/Log.purs and confirm the absence of warnings. If using row polymorphism, try adding a new effect to the call site and confirm the type system either accepts the extension if the constraint is properly propagated or requests an updated row constraint.
Limitations
Row-based effect inference can be subtle; missing an effect in a signature may cause unexpected errors at the call site. Older PureScript versions (pre-0.15) have different row-polymorphism handling; upgrade considerations apply. Row polymorphism may increase compilation time slightly when many row variables are in scope, but the trade-off is stronger static guarantees.