Typed First-Class Traits

Authors Xuan Bi, Bruno C. d. S. Oliveira

Thumbnail PDF


  • Filesize: 0.69 MB
  • 28 pages

Document Identifiers

Author Details

Xuan Bi
  • The University of Hong Kong, Hong Kong, China
Bruno C. d. S. Oliveira
  • The University of Hong Kong, Hong Kong, China

Cite AsGet BibTex

Xuan Bi and Bruno C. d. S. Oliveira. Typed First-Class Traits. In 32nd European Conference on Object-Oriented Programming (ECOOP 2018). Leibniz International Proceedings in Informatics (LIPIcs), Volume 109, pp. 9:1-9:28, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2018)


Many dynamically-typed languages (including JavaScript, Ruby, Python or Racket) support first-class classes, or related concepts such as first-class traits and/or mixins. In those languages classes are first-class values and, like any other values, they can be passed as an argument, or returned from a function. Furthermore first-class classes support dynamic inheritance: i.e. they can inherit from other classes at runtime, enabling programmers to abstract over the inheritance hierarchy. In contrast, type system limitations prevent most statically-typed languages from having first-class classes and dynamic inheritance. This paper shows the design of SEDEL: a polymorphic statically-typed language with first-class traits, supporting dynamic inheritance as well as conventional OO features such as dynamic dispatching and abstract methods. To address the challenges of type-checking first-class traits, SEDEL employs a type system based on the recent work on disjoint intersection types and disjoint polymorphism. The novelty of SEDEL over core disjoint intersection calculi are source level features for practical OO programming, including first-class traits with dynamic inheritance, dynamic dispatching and abstract methods. Inspired by Cook and Palsberg's work on the denotational semantics for inheritance, we show how to design a source language that can be elaborated into Alpuim et al.'s F_{i} (a core polymorphic calculus with records supporting disjoint polymorphism). We illustrate the applicability of SEDEL with several example uses for first-class traits, and a case study that modularizes programming language interpreters using a highly modular form of visitors.

Subject Classification

ACM Subject Classification
  • Software and its engineering → Object oriented languages
  • traits
  • extensible designs


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Javascript. URL: https://www.javascript.com/.
  2. Python. URL: https://www.python.org/.
  3. Racket. URL: https://racket-lang.org/.
  4. Ruby. URL: https://www.ruby-lang.org/en/.
  5. Amal Jamil Ahmed. Semantics of types for mutable state. PhD thesis, Princeton University, 2004. Google Scholar
  6. Eric E. Allen, Jonathan Bannet, and Robert Cartwright. A first-class approach to genericity. In Object-Oriented Programming Systems, Languages and Applications (OOPSLA), 2003. Google Scholar
  7. João Alpuim, Bruno C. d. S. Oliveira, and Zhiyuan Shi. Disjoint polymorphism. In European Symposium on Programming (ESOP), 2017. Google Scholar
  8. Davide Ancona, Giovanni Lagorio, and Elena Zucca. Jam-designing a java extension with mixins. In ACM Transactions on Programming Languages and Systems (TOPLAS), 2003. Google Scholar
  9. Jan Bessai, Boris Düdder, Andrej Dudenhefner, Tzu-Chun Chen, and Ugo de'Liguoro. Typing classes and mixins with intersection types. In Workshop on Intersection Types and Related Systems (ITRS), 2014. Google Scholar
  10. Lorenzo Bettini, Sara Capecchi, and Ferruccio Damiani. On flexible dynamic trait replacement for java-like languages. Science of Computer Programming, 78(7):907-932, 2013. Google Scholar
  11. Lorenzo Bettini and Ferruccio Damiani. Xtraitj: Traits for the java platform. Journal of Systems and Software, 131:419-441, 2017. Google Scholar
  12. Lorenzo Bettini, Ferruccio Damiani, Ina Schaefer, and Fabio Strocco. Traitrecordj: A programming language with traits and records. Science of Computer Programming, 78(5):521-541, 2013. Google Scholar
  13. Xuan Bi, Bruno C. d. S. Oliveira, and Tom Schrijvers. The essence of nested composition. In European Conference on Object-Oriented Programming, 2018. Google Scholar
  14. Viviana Bono, Amit Patel, and Vitaly Shmatikov. A core calculus of classes and mixins. In European Conference on Object-Oriented Programming (ECOOP), 1999. Google Scholar
  15. Gilad Bracha. The programming language jigsaw: mixins, modularity and multiple inheritance. PhD thesis, Dept. of Computer Science, University of Utah, 1992. Google Scholar
  16. Gilad Bracha and William R. Cook. Mixin-based inheritance. In Object-oriented Programming, Systems, Languages and Applications (OOPSLA), 1990. Google Scholar
  17. Gilad Bracha and Gary Lindstrom. Modularity meets inheritance. In International Conference on Computer Languages, pages 282-290. IEEE Computer Society, 1992. Google Scholar
  18. William R. Cook. Anatomy of Programming Languages. The University of Texas, 2013. URL: http://www.cs.utexas.edu/~wcook/anatomy/.
  19. William R. Cook and Jens Palsberg. A denotational semantics of inheritance and its correctness. In Object-Oriented Programming: Systems, Languages and Applications (OOPSLA), 1989. Google Scholar
  20. Mario Coppo, Mariangiola Dezani-Ciancaglini, and Betti Venneri. Functional characters of solvable terms. Mathematical Logic Quarterly, 27(2-6):45-58, 1981. Google Scholar
  21. Stéphane Ducasse, Oscar Nierstrasz, Nathanael Schärli, Roel Wuyts, and Andrew P. Black. Traits: A mechanism for fine-grained reuse. ACM Transactions on Programming Languages and Systems, 28(2):331-388, mar 2006. Google Scholar
  22. Joshua Dunfield. Elaborating intersection and union types. Journal of Functional Programming, 24(2-3):133-165, 2014. Google Scholar
  23. Ecma International. ECMAScript 2015 Language Specification. Ecma International, Geneva, 6th edition, June 2015. URL: http://www.ecma-international.org/ecma-262/6.0/ECMA-262.pdf.
  24. Robert Bruce Findler, John Clements, Cormac Flanagan, Matthew Flatt, Shriram Krishnamurthi, Paul Steckler, and Matthias Felleisen. Drscheme: a programming environment for scheme. J. Funct. Program., 12(2):159-182, 2002. Google Scholar
  25. Kathleen Fisher and John Reppy. A typed calculus of traits. In Workshop on Foundations of Object-oriented Programming, 2004. Google Scholar
  26. Matthew Flatt, Robert Bruce Findler, and Matthias Felleisen. Scheme with classes, mixins, and traits. In Programming Languages and Systems (APLAS), 2006. Google Scholar
  27. Matthew Flatt, Shriram Krishnamurthi, and Matthias Felleisen. Classes and mixins. In Principles of Programming Languages (POPL), 1998. Google Scholar
  28. Timothy Jones, Michael Homer, James Noble, and Kim B. Bruce. Object inheritance without classes. In European Conference on Object-Oriented Programming (ECOOP), 2016. Google Scholar
  29. Giovanni Lagorio, Marco Servetto, and Elena Zucca. Featherweight jigsaw — replacing inheritance by composition in java-like languages. Information and Computation, 214:86-111, 2012. Google Scholar
  30. Joseph Lee, Jonathan Aldrich, Troy Shaw, and Alex Potanin. A theory of tagged objects. In European Conference on Object-Oriented Programming (ECOOP), 2015. Google Scholar
  31. Roberto E Lopez-Herrejon, Don Batory, and William Cook. Evaluating support for features in advanced modularization technologies. In European Conference on Object-Oriented Programming (ECOOP), 2005. Google Scholar
  32. David MacQueen. Modules for standard ML. In Proceedings of the 1984 ACM Symposium on LISP and functional programming - LFP quotesingle84, 1984. Google Scholar
  33. Bertrand Meyer. Eiffel: programming for reusability and extendibility. ACM Sigplan Notices, 22(2):85-94, 1987. Google Scholar
  34. Oscar Nierstrasz, Stéphane Ducasse, and Nathanael Schärli. Flattening traits. Journal of Object Technology, 5(4):129-148, 2006. Google Scholar
  35. James Noble, Andrew P. Black, Kim B. Bruce, Michael Homer, and Timothy Jones. Grace’s inheritance. Journal of Object Technology, 16(2):2:1-35, 2017. Google Scholar
  36. Martin Odersky, Philippe Altherr, Vincent Cremet, Burak Emir, Sebastian Maneth, Stéphane Micheloud, Nikolay Mihaylov, Michel Schinz, Erik Stenman, and Matthias Zenger. An overview of the scala programming language. Technical report, EPFL Lausanne, Switzerland, 2004. Google Scholar
  37. Martin Odersky and Matthias Zenger. Scalable component abstractions. In Object-Oriented Programming: Systems, Languages and Applications (OOPSLA 2005), 2005. Google Scholar
  38. Bruno C. d. S. Oliveira. Modular visitor components: A practical solution to the expression families problem. In European Conference on Object Oriented Programming (ECOOP), 2009. Google Scholar
  39. Bruno C. d. S. Oliveira and William R. Cook. Extensibility for the masses. In European Conference on Object-Oriented Programming (ECOOP), 2012. Google Scholar
  40. Bruno C. d. S. Oliveira, Zhiyuan Shi, and João Alpuim. Disjoint intersection types. In International Conference on Functional Programming (ICFP), 2016. Google Scholar
  41. Bruno C. d. S. Oliveira, Tijs Van Der Storm, Alex Loh, and William R Cook. Feature-oriented programming with object algebras. In European Conference on Object-Oriented Programming (ECOOP), 2013. Google Scholar
  42. Bruno C. d. S. Oliveira, Meng Wang, and Jeremy Gibbons. The visitor pattern as a reusable, generic, type-safe component. In Object Oriented Programming: Systems, Languages and Applications (OOPSLA), 2008. Google Scholar
  43. Garrel Pottinger. A type assignment for the strongly normalizable λ-terms. To HB Curry: essays on combinatory logic, lambda calculus and formalism, pages 561-577, 1980. Google Scholar
  44. Tillmann Rendel, Jonathan Immanuel Brachthäuser, and Klaus Ostermann. From object algebras to attribute grammars. In Object Oriented Programming, Systems Languages and Applications (OOPSLA), 2014. Google Scholar
  45. Andreas Rossberg and Derek Dreyer. Mixin' up the ML module system. ACM Transactions on Programming Languages and Systems, 35(1):1-84, apr 2013. Google Scholar
  46. Nathanael Scharli, St Ducasse, Roel Wuyts, Andrew Black, et al. Traits: The formal model. CSETech, 2003. Google Scholar
  47. Nathanael Schärli, Stéphane Ducasse, Oscar Nierstrasz, and Andrew P Black. Traits: Composable units of behaviour. In European Conference on Object-Oriented Programming (ECOOP), 2003. Google Scholar
  48. Marco Servetto and Elena Zucca. A meta-circular language for active libraries. Science of Computer Programming, 95:219-253, 2014. Google Scholar
  49. Yannis Smaragdakis and Don S. Batory. Mixin-based programming in C++. In Generative and Component-Based Software Engineering (GCSE), 2000. Google Scholar
  50. Charles Smith and Sophia Drossopoulou. Chai: Traits for java-like languages. In Andrew P. Black, editor, European Conference on Object-Oriented Programming (ECOOP), 2005. Google Scholar
  51. Asumu Takikawa, T. Stephen Strickland, Christos Dimoulas, Sam Tobin-Hochstadt, and Matthias Felleisen. Gradual typing for first-class classes. In Object-oriented Programming: Systems, Languages and Applications (OOPSLA), 2012. Google Scholar
  52. Mads Torgersen. The Expression Problem Revisited. In European Conference on Object-Oriented Programming (ECOOP), 2004. Google Scholar
  53. David Ungar and Randall B Smith. Self: the power of simplicity (object-oriented language). In Compcon Spring'88. Thirty-Third IEEE Computer Society International Conference, Digest of Papers, 1988. Google Scholar
  54. Philip Wadler. The expression problem. Java-genericity mailing list, 1998. Google Scholar
  55. Mitchell Wand. Type inference for objects with instance variables and inheritance. Theoretical aspects of object-oriented programming, pages 97-120, 1994. Google Scholar
  56. Pamela Zave. Faq sheet on feature interaction. Link: http://www. research. att. com/~ pamela/faq. html, 1999. Google Scholar