Exception Handlers as Extensible Cases

Matthias Blume; Umut Acar; Wonseok Chae. 7 February, 2008.
Communicated by Dave MacQueen.


Exceptions are an indispensable part of modern programming languages. They are, however, supported poorly, especially by higher-order languages such as Standard ML and Haskell: in both languages a well-typed program can unexpectedly fail due to an uncaught exception. In this paper, we propose a technique for type-safe exception handling. Our approach relies on representing exceptions as sums and assigning exception handlers polymorphic, extensible row types. Based on this representation, we describe an implicitly typed external language EL where well-typed programs do not raise any unhandled exceptions. Since EL relies on sums and polymorphic extensible records to represent exception-handling constructs, the type system of the language is no more complicated than existing languages with polymorphic extensible records. We give a compilation technique based on translating EL into an internal language IL that is a variant of System F extended with extensible records. The translation performs a CPS transformation to represent exception handlers as continuations and relies on duality to transform sums into records. We describe the implementation of a compiler for a concrete language based on EL. The compiler performs full type inference and translates EL-style source code to machine code. Full type inference relieves the programmer from having to provide explicit exception annotations. We believe that this is the first practical proposal for integrating exceptions into the type system of a higher-order language.

Original Document

The original document is available in PDF (uploaded 7 February, 2008 by Dave MacQueen).