Lab note #058 Free Monad Effects and Algebraic Effects

Lab note #058 Free Monad Effects and Algebraic Effects

I'd finished up looking into reactivity (with the exception of data type enforced reactivity, like differential dataflow), and I pulled out code with pedagogical sample code implementing signals and autotracking.

I'd been talking about getting out of rabbit holes, but I don't feel confident that I understand aspects and nuances of algebraic effects, so I decided to look for talks and materials that were either source or accessible.

I took some detours to brush up on monads, lambda calculus, and some funsies about universal construction. Here's the list of what I went over this past week.

My current understanding of effects is simply that it's a way to separate description of what effects you want done, with the interpretation of that effect. This interpretation is done during evaluation and is effectively a dynamic dispatch interrupt–we suspend execution to do something else, and resume when we've finished that something else. This sounds like async/await, but it's more generic. It allows you to abort the handler or resume the execution multiple times from the handler.

There's two ways to do this.

  1. Construct an abstract syntax tree with Free Monads and traverse it with handlers to replace effect descriptions with handler results during evalution.
  2. Suspend execution with a delimited continuation and run the handler, then take the handler result and resume the rest of the computation with the continuation.

All of this is, effectively, disciplined control flow beyond just the typical call stack push and pop.

But I felt like I'm still missing something. I think the last part is probably how the effect types work as a DX to devs, and how it might help find the correct handler.

I also want to see if I'm missing anything by a cursory survey of the influencial papers on effects and algebraic effects. It's likely that I won't understand everything, but I'll try to cover what I can and what I think is important, I'll deep dive with 4o, like I've been doing.