Eliminating spurious error messages using exceptions, polymorphism, and higher-order functions

Authors
Citation
N. Ramsey, Eliminating spurious error messages using exceptions, polymorphism, and higher-order functions, COMPUTER J, 42(5), 1999, pp. 360-372
Citations number
23
Categorie Soggetti
Computer Science & Engineering
Journal title
COMPUTER JOURNAL
ISSN journal
00104620 → ACNP
Volume
42
Issue
5
Year of publication
1999
Pages
360 - 372
Database
ISI
SICI code
0010-4620(1999)42:5<360:ESEMUE>2.0.ZU;2-J
Abstract
Many language processors make assumptions after detecting an error. If the assumptions are invalid, a compiler may issue a cascade of error messages i n which only the first represents a true error in the input; later messages are side effects of the original error. Eliminating such spurious error me ssages requires keeping track of values within the compiler that are not av ailable because of a previously detected error Examples include symbol-tabl e entries, types and intermediate code, This paper presents a discipline fa r tracking unavailable values and avoiding cascading error messages. The di scipline extends the error monad of Spivey [1] and Wadler [2]. The extensio n is expressed formally as a type constructor and combinators written in St andard ML. The type constructor distinguishes intermediate results that are unavailable because of a previously detected error. The combinators transf orm ordinary functions, which assume all intermediate results are available , into functions that silently propagate the unavailability of intermediate results. In an ML implementation, the ML type rules enforce the discipline ; if the compiler writer does not account for a potentially unavailable val ue, the source code of the compiler does not type-check. The cost of the di scipline is negligible. In an experimental compiler, the discipline adds at most 5-10% to the total compile time, and about 1% in the common case in w hich no errors are detected.