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.
- A.W. Appel. Compiling with continuations. Cambridge University Press, New York, NY, USA, 1992. Google Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- K. Bruce. Some challenging typing issues in object-oriented languages. In Electronic notes in Theoretical Computer Science, volume 82(8), 2003.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- M. Flatt. Programming Languages for Reusable Software Components. PhD thesis, Department of Computer Science, Rice University, 1999. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- J. Garrigue. Programming with polymorphic variants. In ACM SIGPLAN Workshop on ML, 1998.Google Scholar
- J. Garrigue. Code reuse through polymorphic variants. In Workshop on Foundations of Software Engineering, Nov. 2000.Google Scholar
- 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 Scholar
- 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 Scholar
- M.P. Jones. Coherence for qualified types. Technical Report YALEU/DCS/RR-989, Yale University, New Haven, Connecticut, USA, 1993.Google Scholar
- M.P. Jones and S.P. Jones. Lightweight extensible records for Haskell, 1999.Google Scholar
- 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 Scholar
Digital Library
- X. Leroy. {caml-list} cyclic types. http://caml.inria.fr/pub/ml-archives/caml-list/,Jan. 2005.Google Scholar
- 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 Scholar
Digital Library
- R. Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 13(3):348--375, 1978.Google Scholar
Cross Ref
- R. Milner, M. Tofte, R. Harper, and D. MacQueen. The Definition of Standard ML (Revised). MIT Press, Cambridge, MA, 1997. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- A. Ohori. A simple semantics for ml polymorphism. In FPCA, pages 281--292, 1989. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- A. Ohori. A polymorphic record calculus and its compilation. ACM Trans. Program. Lang. Syst., 17(6):844--895, 1995. Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- P. Wadler. The expression problem. Email to the Java Genericity mailing list, Dec. 1998.Google Scholar
- M. Wand. Complete type inference for simple objects. In Proceedings of the IEEE Symposium on Logic in Computer Science, Ithaca, NY, June 1987.Google Scholar
- M. Wand. Type inference for record concatenation and multiple inheritance. Information and Computation, 93(1):1--15, 1991. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Index Terms
Extensible programming with first-class cases
Recommendations
Extensible programming with first-class cases
ICFP '06: Proceedings of the eleventh ACM SIGPLAN international conference on Functional programmingWe 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 ...
Exception Handlers as Extensible Cases
APLAS '08: Proceedings of the 6th Asian Symposium on Programming Languages and SystemsExceptions 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 ...







Comments