skip to main content
article

Extensible programming with first-class cases

Published:16 September 2006Publication History
Skip Abstract Section

Abstract

We present language mechanisms for polymorphic, extensible records and their exact dual, polymorphic sums with extensible first-class cases. These features make it possible to easily extend existing code with new cases. In fact, such extensions do not require any changes to code that adheres to a particular programming style. Using that style, individual extensions can be written independently and later be composed to form larger components. These language mechanisms provide a solution to the expression problem.We study the proposed mechanisms in the context of an implicitly typed, purely functional language PolyR. We give a type system for the language and provide rules for a 2-phase transformation: first into an explicitly typed λ-calculus with record polymorphism, and finally to efficient index-passing code. The first phase eliminates sums and cases by taking advantage of the duality with records.We implement a version of PolyR extended with imperative features and pattern matching - we call this language MLPolyR. Programs in MLPolyR require no type annotations - the implementation employs a reconstruction algorithm to infer all types. The compiler generates machine code (currently for PowerPC) and optimizes the representation of sums by eliminating closures generated by the dual construction.

References

  1. A.W. Appel. Compiling with continuations. Cambridge University Press, New York, NY, USA, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. A.W. Appel and D.B. MacQueen. Standard ML of New Jersey. In M. Wirsing, editor, 3rd International Symp. on Prog. Lang. Implementation and Logic Programming, pages 1--13, New York, Aug. 1991. Springer-Verlag.Google ScholarGoogle ScholarCross RefCross Ref
  3. F. Bourdoncle and S. Merz. Type-checking higher-order polymorphic multi-methods. In Conference Record of POPL '97: The 24th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pages 302--315, Paris, France, 15-17 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. K. Bruce. Some challenging typing issues in object-oriented languages. In Electronic notes in Theoretical Computer Science, volume 82(8), 2003.Google ScholarGoogle Scholar
  5. L. Cardelli and J.C. Mitchell. Operations on records. In C.A. Gunter and J.C. Mitchell, editors, Theoretical Aspects of Object-Oriented Programming: Types, Semantics, and Language Design, pages 295--350. The MIT Press, Cambridge, MA, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. R.B. Findler and M. Flatt. Modular object-oriented programming with units and mixins. In ICFP '99: Proceedings of the fourth ACM SIGPLAN international conference on Functional programming, volume 34(1) of SIGPLAN, pages 94--104, New York, NY, June 1999. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. C. Flanagan, A. Sabry, B.F. Duba, and M. Felleisen. The Essence of Compiling with Continuations. In 1993 Conference on Programming Language Design and Implementation., pages 21--25, June 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. M. Flatt. Programming Languages for Reusable Software Components. PhD thesis, Department of Computer Science, Rice University, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. T. Freeman and F. Pfenning. Refinement types for ML. In PLDI '91: Proceedings of the ACM SIGPLAN 1991 conference on Programming language design and implementation, pages 268--277, New York, NY, USA, 1991. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. J. Garrigue. Programming with polymorphic variants. In ACM SIGPLAN Workshop on ML, 1998.Google ScholarGoogle Scholar
  11. J. Garrigue. Code reuse through polymorphic variants. In Workshop on Foundations of Software Engineering, Nov. 2000.Google ScholarGoogle Scholar
  12. B.R. Gaster and M.P. Jones. A polymorphic type system for extensible records and variants. Technical Report NOTTCS-TR-96-3, Department of Computer Science, University of Nottingham, 1996.Google ScholarGoogle Scholar
  13. K. Gowani and M. Blume. Writing a garbage collector for the MLPolyR compiler, July 2005. Final report on independent study project in the CSPP program.Google ScholarGoogle Scholar
  14. M.P. Jones. Coherence for qualified types. Technical Report YALEU/DCS/RR-989, Yale University, New Haven, Connecticut, USA, 1993.Google ScholarGoogle Scholar
  15. M.P. Jones and S.P. Jones. Lightweight extensible records for Haskell, 1999.Google ScholarGoogle Scholar
  16. S. Krishnamurthi, M. Felleisen, and D.P. Friedman. Synthesizing Object-Oriented and Functional Design to Promote ReUse. In European Conference on Object-Oriented Programming, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. X. Leroy. {caml-list} cyclic types. http://caml.inria.fr/pub/ml-archives/caml-list/,Jan. 2005.Google ScholarGoogle Scholar
  18. T. Millstein, C. Bleckner, and C. Chambers. Modular typechecking for hierarchically extensible datatypes and functions. In ICFP '02: Proceedings of the seventh ACM SIGPLAN international conference on Functional programming, pages 110--122, New York, NY, USA, 2002. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. R. Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 13(3):348--375, 1978.Google ScholarGoogle ScholarCross RefCross Ref
  20. R. Milner, M. Tofte, R. Harper, and D. MacQueen. The Definition of Standard ML (Revised). MIT Press, Cambridge, MA, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. I.N.I. Adams, D.H. Bartley, G. Brooks, R.K. Dybvig, D.P. Friedman, R. Halstead, C. Hanson, C.T. Haynes, E. Kohlbecker, D. Oxley, K.M. Pitman, G.J. Rozas, J.G.L. Steele, G.J. Sussman, M. Wand, and H. Abelson. Revised5 report on the algorithmic language scheme. SIGPLAN Not., 33(9):26--76, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. M. Odersky and P. Wadler. Pizza into Java: Translating theory into practice. In Proceedings of the 24th ACM Symposium on Principles of Programming Languages (POPL'97), Paris, France, pages 146--159. ACM Press, New York (NY), USA, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. A. Ohori. A simple semantics for ml polymorphism. In FPCA, pages 281--292, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. A. Ohori. A compilation method for ml-style polymorphic record calculi. In POPL '92: Proceedings of the 19th ACM SIGPLAN-SIGACT symposium on Principles of programming languages, pages 154--165, New York, NY, USA, 1992. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. A. Ohori. A polymorphic record calculus and its compilation. ACM Trans. Program. Lang. Syst., 17(6):844--895, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. D. Rémy. Type inference for records in a natural extension of ML. Research Report 1431, Institut National de Recherche en Informatique et Automatisme, Rocquencourt, BP 105, 78 153 Le Chesnay Cedex, France, may 1991.Google ScholarGoogle Scholar
  27. D. Rémy and J. Vouillon. Objective ML: An effective object-oriented extension to ML. Theory And Practice of Objects Systems, 4(1):27--50, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. J. Reppy and J. Riecke. Simple objects for Standard ML. In Proceedings of the ACM SIGPLAN '96 Conference on Programming Language Design and Implementation, pages 171--180, Philadelphia, Pennsylvania, 21-24 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. M. Torgersen. The expression problem revisited: Four new solutions using generics. In M. Odersky, editor, ECOOP 2004-Object-Oriented Programming, 18th European Conference, Oslo, Norway, Proceedings, volume 3086 of LNCS, pages 123--143, New York, NY, July 2004. Springer-Verlag.Google ScholarGoogle Scholar
  30. P. Wadler. The expression problem. Email to the Java Genericity mailing list, Dec. 1998.Google ScholarGoogle Scholar
  31. M. Wand. Complete type inference for simple objects. In Proceedings of the IEEE Symposium on Logic in Computer Science, Ithaca, NY, June 1987.Google ScholarGoogle Scholar
  32. M. Wand. Type inference for record concatenation and multiple inheritance. Information and Computation, 93(1):1--15, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. M. Zenger and M. Odersky. Extensible algebraic datatypes with defaults. In ICFP '01: Proceedings of the sixth ACM SIGPLAN international conference on Functional programming, pages 241--252, New York, NY, USA, 2001. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. M. Zenger and M. Odersky. Independently extensible solutions to the expression problem. In The 12th International Workshop on Foundations of Object-Oriented Languages (FOOL 12), Long Beach, California, 2005. ACM.Google ScholarGoogle Scholar

Index Terms

  1. Extensible programming with first-class cases

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    • Published in

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 41, Issue 9
      Proceedings of the 2006 ICFP conference
      September 2006
      296 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/1160074
      Issue’s Table of Contents
      • cover image ACM Conferences
        ICFP '06: Proceedings of the eleventh ACM SIGPLAN international conference on Functional programming
        September 2006
        308 pages
        ISBN:1595933093
        DOI:10.1145/1159803
        • General Chair:
        • John Reppy,
        • Program Chair:
        • Julia Lawall

      Copyright © 2006 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 16 September 2006

      Check for updates

      Qualifiers

      • article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!