Due: Wednesday, December 4, 2013
Write a function to simulate the "try ... catch ..." exception-handling construct using letcc/throw. The function
should have the following type:
$trycatch : \forall t_1.\forall t_2.(t_2 \; cont \to t_1) \to (t_2 \to t_1) \to t_1$
The expected behavior for an invocation is as follows:
$trycatch \;(body) \; (handler)$
should pass a
continuation $k$ to $body$ and proceed to evaluate it; if $body$ evaluates to $a$ then that
should be the result of the overall expression; if $body$ throws a value $b$ to the
continuation $k$ then the result of the overall expression should be $handler \; (b)$.
Reynolds, exercise 12.4. Use letcc/throw instead of callcc/throw, and have $test$ return pairs of natural numbers $\langle n_1, n_2 \rangle$ instead of $@ \; n_1 \; n_2$. The type of $F$ is $(nat \to nat) \to (nat \to nat) \to nat$.
Sample solutions are here and here as well as on the Zoo machine /c/cs430/as/as7/as7-sol.*.