This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Typed Compilation of Recursive Datatypes * Joseph C. Vanderwaart Derek Dreyer Leaf Petersen Karl Crary Robert Harper Perry Cheng † School of Computer Science Carnegie Mellon University Pittsburgh, PA 15213 Abstract Standard ML employs an opaque (or generative) semantics of datatypes, in which every datatype declaration produces a new type that is different from any other type, including other identically de- fined datatypes. A natural way of accounting for this is to con- sider datatypes to be abstract. When this interpretation is applied to type-preserving compilation, however, it has the unfortunate con- sequence that datatype constructors cannot be inlined, substantially increasing the run-time cost of constructor invocation compared to a traditional compiler. In this paper we examine two approaches to eliminating function call overhead from datatype constructors. First, we consider a transparent interpretation of datatypes that does away with generativity, altering the semantics of SML; and sec- ond, we propose an interpretation of datatype constructors as coer- cions, which have no run-time effect or cost and faithfully imple- ment SML semantics. Categories and Subject Descriptors D.3.3 [ Programming Languages ]: Language Constructs and Fea- tures— Abstract data types ; D.3.4 [ Programming Languages ]: Processors— Compilers ; F.3.3 [ Logics and Meanings of Pro- grams ]: Studies of Program Constructs— Type structure General Terms Languages, Theory, Performance Keywords Typed compilation, Standard ML, recursive types, coercions * The ConCert Project is supported by the National Science Foundation under grant number 0121633: ”ITR/SY+SI: Language Technology for Trustless Software Dissemination”. † IBM, TJ Watson, P.O. Box 704, Yorktown, NY 10598 Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. TLDI’03, January 18, 2003, New Orleans, Louisiana, USA. Copyright 2003 ACM 1-58113-649-8/03/0001 ...$5.00 1 Introduction The programming language Standard ML (SML)  provides a distinctive mechanism for defining recursive types, known as a datatype declaration . For example, the following declaration de- fines the type of lists of integers: datatype intlist = Nil | Cons of int * intlist This datatype declaration introduces the type intlist and two constructors : Nil represents the empty list, and Cons combines an integer and a list to produce a new list. For instance, the expres- sion Cons (1, Cons (2, Cons (3,Nil))) has type intlist and corresponds to the list [ 1 , 2 , 3 ] . Values of this datatype are de- constructed by a case analysis that examines a list and determines whether it was constructed with...
View Full Document
This note was uploaded on 02/21/2011 for the course CS 542 taught by Professor Dr. thomas during the Spring '10 term at SUNY Buffalo.
- Spring '10
- Dr. Thomas
- Computer Science