Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.1145/1291201.1291212acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
Article

A type-preserving closure conversion in haskell

Published: 30 September 2007 Publication History
  • Get Citation Alerts
  • Abstract

    The use of typed intermediate languages can significantly increase the reliability of a compiler. By type-checking the code produced at each transformation stage, one can identify bugs in the compiler that would otherwise be much harder to find. Also it guarantees that any property that was enforced by the source-level type-system is holds also or the generated code. Recently, several people have tried to push this effort a bit further by verifying formally that the compiler indeed preserves typing. This is usually done with proof assistants or experimental languages.
    Instead, we decided to use Haskell (with GHC's extensions), to see how far we can go with a more mainstream system, supported by robust compilers and plentiful libraries. This article presents one part of our type preserving compiler, namely the closure conversion and its associated hoisting phase, where we use GADTs to let Haskell's type checker verify the we obey the object language's typing rules and that we correctly preserve types from one phase to the other.
    This should be both a good showcase as well as a good stress test for GADTs, so we also discuss our experience, as well as some trade-offs in the choice of representation, namely between higher-order abstract syntax (HOAS) and a first order representation (i.e. de Bruijn indices) and justify our choice of a de Bruijn representation. We incidentally present a type preserving conversion from HOAS (used in earlier phases of the compiler[6]) to a de Bruijn representation.

    References

    [1]
    Chiyan Chen and Hongwei Xi. Implementing typeful program transformations. In PEPM '03: Proceedings of the 2003 ACM SIGPLAN workshop on Partial evaluation and semantics-based program manipulation, pages 20--28, New York, NY, USA, 2003. ACM Press.
    [2]
    James Cheney and Ralf Hinze. First-class phantom types. Technical Report CUCIS TR2003-1901, Cornell University, 2003.
    [3]
    Adam Chlipala. A certified type-preserving compiler from lambda calculus to assembly language. In PLDI'07: Proceedings of the ACM SIGPLAN 2007 Conference on Programming Language Design and Implementation, June 2007.
    [4]
    Iavor S. Diatchki and Mark P. Jones. Strongly typed memory areas: Programming systems-level data structures in a functional language. In Haskell Workshop, pages 72--83. ACM Press, Oct 2006.
    [5]
    Leonidas Fegaras and Tim Sheard. Revisiting catamorphisms over datatypes with embedded functions (or, programs from outer space). In Conf. Record 23rd ACM SIGPLAN/SIGACT Symp. on Principles of Programming Languages, POPL '96, St. Petersburg Beach, FL, USA, 21-24 Jan. 1996, pages 284--294. ACM Press, New York, 1996.
    [6]
    Louis-Julien Guillemette and Stefan Monnier. Type-safe code transformations in haskell. In Programming Languages meets Program Verification, volume 174(7) of Electronic Notes in Theoretical Computer Science, pages 23--39, Aug 2006.
    [7]
    Nadeem Abdul Hamid, Zhong Shao, Valery Trifonov, Stefan Monnier, and Zhaozhong Ni. A syntactic approach to foundational proof-carrying code. In Annual Symposium on Logic in Computer Science, pages 89--100, Copenhagen, Denmark, July 2002.
    [8]
    Xavier Leroy. Unboxed objects and polymorphic typing. In Symposium on Principles of Programming Languages, pages 177--188, January 1992.
    [9]
    Xavier Leroy. Formal certification of a compiler back-end or: programming a compiler with a proof assistant. In Symposium on Principles of Programming Languages, pages 42--54, New York, NY, USA, January 2006. ACM Press.
    [10]
    Nathan Linger and Tim Sheard. Programming with static invariants in omega. Unpublished, 2004.
    [11]
    Yasuhiko Minimide, Greg Morrisett, and Robert Harper. Typed closure conversion. In Symposium on Principles of Programming Languages, pages 271--283. ACM Press, January 1996.
    [12]
    Greg Morrisett, David Walker, Karl Crary, and Neal Glew. From system F to typed assembly language. In Symposium on Principles of Programming Languages, pages 85--97, January 1998.
    [13]
    Greg Morrisett, David Walker, Karl Crary, and Neal Glew. From System F to typed assembly language. ACM Transactions on Programming Languages and Systems, 21(3):527--568, 1999.
    [14]
    George C. Necula. Proof-carrying code. In Conference Record of POPL '97: The 24th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 106--119, Paris, France, Jan 1997.
    [15]
    Emir Pasalic. The Role of Type Equality in Meta-Programming. PhD thesis, Oregon Health and Sciences University, The OGI School of Science and Engineering, 2004.
    [16]
    Frank Pfenning and Conal Elliott.Higher-order abstract syntax.In PLDI '88: Proceedings of the ACM SIGPLAN 1988 conference on Programming Language design and Implementation, pages 199--208, New York, NY, USA, 1988. ACM Press.
    [17]
    Zhong Shao. Flexible representation analysis. In International Conference on Functional Programming, page 85--98. ACM Press, June 1997.
    [18]
    Zhong Shao. An overview of the FLINT/ML compiler. In International Workshop on Types in Compilation, June 1997.
    [19]
    Zhong Shao and Andrew W. Appel. Space-efficient closure representations. In Proc. 1994 ACM Conf. on Lisp and Functional Programming, pages 150--161, Orlando, FL, June 1994.
    [20]
    Zhong Shao and Andrew W. Appel. A type-based compiler for Standard ML. In Symposium on Programming Languages Design and Implementation, pages 116--129, La Jolla, CA, June 1995. ACM Press.
    [21]
    Zhong Shao, Bratin Saha, Valery Trifonov, and Nikolaos Papaspyrou. A type system for certified binaries. In Symposium on Principles of Programming Languages, pages 217--232, January 2002.
    [22]
    Tim Sheard and Emir Pasalic. Meta-programming with built-in type equality. In Logical Frameworks and Meta-Languages, Cork, July 2004.
    [23]
    Martin Sulzmann, Manuel M. T. Chakravarty, Simon Peyton Jones, and Kevin Donnelly. System F with type equality coercions. In Types in Language Design and Implementation, pages 53--66, Jan 2007.
    [24]
    David Tarditi, Greg Morrisett, Perry Cheng, Christopher Stone, Robert Harper, and Peter Lee. TIL: A type-directed optimizing compiler for ML. In Symposium on Programming Languages Design and Implementation, pages 181--192, Philadelphia, PA, May 1996. ACM Press.
    [25]
    Geoffrey Washburn and Stephanie Weirich. Boxes go bananas: Encoding higher-order abstract syntax with parametric polymorphism. In Proceedings of the Eighth ACM SIGPLAN International Conference on Functional Programming, pages 249--262, Uppsala, Sweden, August 2003. ACM SIGPLAN.
    [26]
    Hongwei Xi, Chiyan Chen, and Gang Chen. Guarded recursive datatype constructors. In Symposium on Principles of Programming Languages, pages 224--235, New Orleans, LA, January 2003.

    Cited By

    View all

    Index Terms

    1. A type-preserving closure conversion in haskell

      Recommendations

      Comments

      Information & Contributors

      Information

      Published In

      cover image ACM Conferences
      Haskell '07: Proceedings of the ACM SIGPLAN workshop on Haskell workshop
      September 2007
      126 pages
      ISBN:9781595936745
      DOI:10.1145/1291201
      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. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

      Sponsors

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      Published: 30 September 2007

      Permissions

      Request permissions for this article.

      Check for updates

      Author Tags

      1. compilation
      2. de bruijn
      3. higher-order abstract syntax
      4. typed assembly language

      Qualifiers

      • Article

      Conference

      ICFP07
      Sponsor:

      Acceptance Rates

      Overall Acceptance Rate 57 of 143 submissions, 40%

      Upcoming Conference

      ICFP '24

      Contributors

      Other Metrics

      Bibliometrics & Citations

      Bibliometrics

      Article Metrics

      • Downloads (Last 12 months)3
      • Downloads (Last 6 weeks)0
      Reflects downloads up to 11 Aug 2024

      Other Metrics

      Citations

      Cited By

      View all
      • (2013)Names for freeACM SIGPLAN Notices10.1145/2578854.250378048:12(13-24)Online publication date: 23-Sep-2013
      • (2013)Names for freeProceedings of the 2013 ACM SIGPLAN symposium on Haskell10.1145/2503778.2503780(13-24)Online publication date: 23-Sep-2013
      • (2012)Programming with binders and indexed data-typesProceedings of the 39th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages10.1145/2103656.2103705(413-424)Online publication date: 25-Jan-2012
      • (2012)Programming with binders and indexed data-typesACM SIGPLAN Notices10.1145/2103621.210370547:1(413-424)Online publication date: 25-Jan-2012
      • (2009)Unembedding domain-specific languagesProceedings of the 2nd ACM SIGPLAN symposium on Haskell10.1145/1596638.1596644(37-48)Online publication date: 3-Sep-2009
      • (2008)A type-preserving compiler in HaskellProceedings of the 13th ACM SIGPLAN international conference on Functional programming10.1145/1411204.1411218(75-86)Online publication date: 20-Sep-2008
      • (2008)A type-preserving compiler in HaskellACM SIGPLAN Notices10.1145/1411203.141121843:9(75-86)Online publication date: 20-Sep-2008

      View Options

      Get Access

      Login options

      View options

      PDF

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader

      Media

      Figures

      Other

      Tables

      Share

      Share

      Share this Publication link

      Share on social media