Hacker News new | ask | show | jobs
by maciejpirog 1582 days ago
Well... it is the best form I could come up with. My interest regarding this project is mostly in usable programmer-level abstractions, so I am very open to any ideas of what kind of API would be better. I'd be super-happy to discuss any alternatives.

Background: In this implementation the use of inheritance is not just for the sake of it ("because it's C++"), but because it gives me type-safety. When you program with handlers, there are a lot of types floating around (the type of the handled computation, the answer type of the handler, the return types of the commands), and I want the compiler to keep track of those. The best option I could find is to make handlers classes that derive from an abstract template, which forces the handler to have the appropriate command/return clauses with appropriate types.

Folks familiar with effect handlers in functional programming might be suspicious about handlers living on two levels, as they are defined as classes but then you handle a computation with a particular object of that class. But it is not a new idea (cf. Pablo Inostroza, T. Storm "JEff: objects for effect"), and this is a much more natural way to express stateful handlers than parameterised handlers in FP.