I feel like noone ever mentions a massive advantages of direct-style effects

05 July 2024

And that is that effect-polymorphic functions can also be used as pure functions.

In Haskell, where we use Monads, the universe is essentially split in two: there are pure functions like map, fold, filter and then there are monadic versions of the same functions that are polymorphic over some monad (or Applicative) like mapM/traverse, foldM, filterM/wither.

This isn’t as bad as it sounds since it is still possible to recover the pure variant by instantiating the monad with Identity, but this requires some wrapping/unwrapping so in practice there are usually still pure variants defined for every effect-polymorphic function and, crucially, functions are pure instead of effect-polymorphic by default.

With direct style effects, there usually isn’t much a a reason not to define effect-polymorphic functions unless they actually have to be pure, so programmers should pretty much never be limited by libraries not exposing an effectful version of some function and library authors shouldn’t even have to think about exposing effect-polymorphic variants.