The key approach involves isolating the effects through a continuation and utilizing try/catch as a handler or control flow mechanism.
I acknowledge that the final outcome may seem convoluted; however, its purpose is to demonstrate the semantic model's capacity to accommodate such constructs.
using System
data tick
def do_tick = [K -> throw (tick K)]
def handle_tick = [N (tick K) -> try K N catch handle_tick (N+1)]
def main = try do_tick [N -> do_tick ((+) N)] catch handle_tick 1
This was modelled after the Koka abstract machine but the more I look at it, the less that makes sense since on first glance it looks like you can compile everything out to continuations.
ReplyDelete