Hi everyone đź‘‹
I am fairly new to OCaml and currently looking at the new effect system. In the docs, effect handlers are described as a generalisation of exception handlers. This reminded me about the common advice to not use exceptions to model control flow (with which I personally definitely agree). Now I’m wondering if this applies in a similar way to algebraic effects. What are your opinions on using effect handlers to model control flow?
To make it more concrete, think about a reasonably complex board game (i.e. chess) which is supposed to have multiple different user interfaces. It’d be great to contain as much game logic as possible in the core module, without leaking any view-specific assumptions in there. To achieve that, we could introduce an effect for the user interaction, which is performed by the core module and handled separately for each UI-implementation. This lets us model the full game-flow in the core module in a subjectively natural way. Whenever we expect the user to interact, we just perform our effect instead of interrupting the current process in an intermediate state.
I hope this is somewhat understandable and I am excited to hear about your thoughts on this. Please correct me, if you find I made inaccurate assumptions.
Cheers ✌️