Hacker News new | ask | show | jobs
by tel 384 days ago
They're pretty similar, but with different ergonomics. Algebraic effects are similar to some kind of "free" monad technique, but built in. For being built in they have nicer syntax and better composability, often. You can achieve the same in a language suitably dedicated to monadic approaches (Haskell being the poster child here) but it helps to have type class inference (giving you mtl-like composability) and built-in bind syntax a la Haskell's `do` or Scala's `for`.
2 comments

Interesting. Thank you for your detailed explanation.

A related Scala-specific technique for this problem category is employing the Stackable Trait Pattern[0] to provide a functional style AOP[1] mechanism. Done carefully, effects (aspects) can be defined independent of specific logic as well as composed with provable invocation order.

Note that the references cited are for those reading this thread and not assumed to be required for the person addressed.

0 - https://www.artima.com/articles/scalas-stackable-trait-patte...

1 - https://en.wikipedia.org/wiki/Aspect-oriented_programming

What is "mtl"?
Sorry, Haskell’s “monad transformer library”. One of the earliest approaches to composability of multiple monadic effects. It’s pretty similar to an algebraic effect system allowing you to write effectual computations with types like `(Error m, Nondet m, WithState App m) => m ()` to indicate a computation that returns nothing but must be executed with access to error handling, nondeterminism, and access to the App type as state.

There are a few drawbacks to it, but it is a pretty simple way to get 80% of the ergonomics of algebraic effects (in Haskell).