Exception Handlers as Extensible Cases

Exceptions are an indispensable part of modern programming languages. They are, however, handled poorly, especially by higherorder 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. EL relies on sums, extensible records, and polymorphism to represent exceptionhandling, and its type system is no more complicated than that for existing languages with polymorphic extensible records. EL is translated 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. It also relies on duality to transform sums into records. (The details for this translation are given in an accompanying technical report.) 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. 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.

[1]  Luca Cardelli,et al.  Modula-3 Report. , 1988 .

[2]  Juan Carlos Guzman,et al.  An extended type system for exceptions , 1994 .

[3]  Kwangkeun Yi,et al.  An Abstract Interpretation for Estimating Uncaught Exceptions in Standard ML Programs , 1998, Sci. Comput. Program..

[4]  François Pessaux,et al.  Type-based analysis of uncaught exceptions , 2000, TOPL.

[5]  Andrew W. Appel,et al.  Standard ML of New Jersey , 1991, PLILP.

[6]  Craig Schaffert,et al.  CLU Reference Manual , 1984, Lecture Notes in Computer Science.

[7]  Nick Benton,et al.  Semantics of an effect analysis for exceptions , 2007, TLDI '07.

[8]  Atsushi Ohori,et al.  A polymorphic record calculus and its compilation , 1995, TOPL.

[9]  J. L. Lions ARIANE 5 Flight 501 Failure: Report by the Enquiry Board , 1996 .

[10]  Robert Hieb,et al.  The Revised Report on the Syntactic Theories of Sequential Control and State , 1992, Theor. Comput. Sci..

[11]  Guy L. Steele,et al.  Java Language Specification, Second Edition: The Java Series , 2000 .

[12]  Nick Benton,et al.  Exceptional syntax , 2001, Journal of Functional Programming.

[13]  Guy L. Steele,et al.  The Java Language Specification , 1996 .

[14]  Jeffrey S. Foster,et al.  Tracking down Exceptions in Standard ML Programs , 1998 .

[15]  Emden R. Gansner,et al.  The standard ML basis library , 2002 .

[16]  Andrew W. Appel,et al.  Compiling with Continuations , 1991 .

[17]  Fritz Henglein,et al.  Type inference with polymorphic recursion , 1993, TOPL.

[18]  Umut A. Acar,et al.  Extensible programming with first-class cases , 2006, ICFP '06.

[19]  Kwangkeun Yi,et al.  Towards a Cost-Effective Estimation of Uncaught Exceptions in SML Programs , 1997, SAS.

[20]  Karl Crary,et al.  Towards a mechanized metatheory of standard ML , 2007, POPL '07.