I didn't implement exceptions right, yet. Throws and catches are factored out but catches catch the exception local in the term. I looked at call-cc and reset-shift, couldn't decide, and, once again, I am going for my own most straightforward implementation described below.
A ((try E0 catch E1) exc) block is roughly translated to (R (λs. E0 (λx.s (E1 x)))) which evaluates to ((λs. E0 (λx. s (E1 x))) Sk) , where Sk is a control object holding the continuation of the original block. It looks the most like reset-shift I guess. The difference is that, as far as I know, reset-shift is a syntactical addition to lambda calculus, whereas these combinators model roughly the same, but depend on call-by-value evaluation to express a control operator which you can't model directly syntactically using common combinators.
R takes a function f and rewrites to f Sk. Sk takes a value v and rewrites to v, but escapes the local context up to the point R was applied.
I didn't implement it yet. Worried a bit about the shift combinator escaping the local context.
013110: Convinced myself, and implemented it. Since the try part of a try-catch can only evaluate to a value or an exception, the exception handler is either applied, or not, so should be properly discarded.
Food is a nice idea sometimes too.
No comments:
Post a Comment