Practical Optional Types for Clojure

  • Ambrose Bonnaire-Sergeant
  • Rowan Davies
  • Sam Tobin-Hochstadt
Part of the Lecture Notes in Computer Science book series (LNCS, volume 9632)


Typed Clojure is an optional type system for Clojure, a dynamic language in the Lisp family that targets the JVM. Typed Clojure enables Clojure programmers to gain greater confidence in the correctness of their code via static type checking while remaining in the Clojure world, and has acquired significant adoption in the Clojure community. Typed Clojure repurposes Typed Racket’s occurrence typing, an approach to statically reasoning about predicate tests, and also includes several new type system features to handle existing Clojure idioms.

In this paper, we describe Typed Clojure and present these type system extensions, focusing on three features widely used in Clojure. First, multimethods provide extensible operations, and their Clojure semantics turns out to have a surprising synergy with the underlying occurrence typing framework. Second, Java interoperability is central to Clojure’s mission but introduces challenges such as ubiquitous null; Typed Clojure handles Java interoperability while ensuring the absence of null-pointer exceptions in typed programs. Third, Clojure programmers idiomatically use immutable dictionaries for data structures; Typed Clojure handles this with multiple forms of heterogeneous dictionary types. We provide a formal model of the Typed Clojure type system incorporating these and other features, with a proof of soundness. Additionally, Typed Clojure is now in use by numerous corporations and developers working with Clojure, and we present a quantitative analysis on the use of type system features in two substantial code bases.


Type System Proof System Typing Rule Java Virtual Machine Type Check 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


  1. 1.
    Allende, E., Callau, O., Fabry, J., Tanter, É., Denker, M.: Gradual typing for Smalltalk. Sci. Comput. Program. 96, 52–69 (2014)CrossRefGoogle Scholar
  2. 2.
    Bonnaire-Sergeant, A.: contributors, core.typed.
  3. 3.
    Cardelli, L., Mitchell, J.C.: Operations on records. Math. Struct. Comput. Sci. 1, 3–48 (1991)MathSciNetCrossRefzbMATHGoogle Scholar
  4. 4.
    Chambers, C.: Object-oriented multi-methods in Cecil. In: Proceedings of the ECOOP (1992)Google Scholar
  5. 5.
    Chambers, C., Leavens, G.T.: Typechecking and modules for multi-methods. In: Proc. OOPSLA (1994)Google Scholar
  6. 6.
    Chugh, R., Herman, D., Jhala, R.: Dependent types for JavaScript. In: Proceedings of the OOPSLA (2012)Google Scholar
  7. 7.
    CircleCI: CircleCI.
  8. 8.
    CircleCI: Why we’re supporting Typed Clojure, and you should too! (September 2013).
  9. 9.
    CircleCI; O’Morain, M.: Why we’re no longer using core.typed (September 2015).
  10. 10.
    Facebook: Hack language specification. Technical report, Facebook (2014)Google Scholar
  11. 11.
    Facebook: Flow language specification. Technical report, Facebook (2015)Google Scholar
  12. 12.
    Harper, R., Pierce, B.: A record calculus based on symmetric concatenation. In: Proceedings of the POPL (1991)Google Scholar
  13. 13.
    Hickey, R.: The Clojure programming language. In: Proceedings of the DLS (2008)Google Scholar
  14. 14.
    Hickey, R.: Clojure sequence documentation (February 2015).
  15. 15.
    Lehtosalo, J.: mypy.
  16. 16.
    Lerner, B.S., Politz, J.G., Guha, A., Krishnamurthi, S.: TeJaS: retrofitting type systems for JavaScript. In: DLS 2013, Proceedings of the 9th Symposium on Dynamic Languages, pp. 1–16. ACM, New York, NY, USA (2013).
  17. 17.
    Lucassen, J.M., Gifford, D.K.: Polymorphic effect systems. In: Proceedings of the POPL (1988)Google Scholar
  18. 18.
    Maidl, A.M., Mascarenhas, F., Ierusalimschy, R.: Typed Lua: an optional type system for Lua. In: Proceedings of the Dyla (2014)Google Scholar
  19. 19.
    Microsoft: Typescript language specification. Technical report Version 1.4, Microsoft (2014)Google Scholar
  20. 20.
    Millstein, T., Chambers, C.: Modular statically typed multimethods. In: Information and Computation. pp. 279–303. Springer-Verlag (2002)Google Scholar
  21. 21.
    Odersky, M., Cremet, V., Dragos, I., Dubochet, G., Emir, B., McDirmid, S., Micheloud, S., Mihaylov, N., Schinz, M., Stenman, E., Spoon, L., Zenger, M., et al.: An overview of the Scala programming language, 2nd edn, Technical report, EPFL Lausanne, Switzerland (2006)Google Scholar
  22. 22.
    Strickland, T.S., Tobin-Hochstadt, S., Felleisen, M.: Practical variable-arity polymorphism. In: Castagna, G. (ed.) ESOP 2009. LNCS, vol. 5502, pp. 32–46. Springer, Heidelberg (2009)CrossRefGoogle Scholar
  23. 23.
    Tobin-Hochstadt, S., Felleisen, M.: The design and implementation of Typed Scheme. In: Proceedings of the POPL (2008)Google Scholar
  24. 24.
    Tobin-Hochstadt, S., Felleisen, M.: Logical types for untyped languages. In: ICFP 2010, Proceedings of the ICFP (2010)Google Scholar
  25. 25.
    Vitousek, M.M., Kent, A.M., Siek, J.G., Baker, J.: Design and evaluation of gradual typing for Python. In: Proc. DLS (2014)Google Scholar
  26. 26.
    Wand, M.: Type inference for record concatenation and multiple inheritance (1989)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2016

Authors and Affiliations

  • Ambrose Bonnaire-Sergeant
    • 1
  • Rowan Davies
    • 2
  • Sam Tobin-Hochstadt
    • 1
  1. 1.Indiana UniversityBloomingtonUSA
  2. 2.Omnia TeamCommonwealth Bank of AustraliaSydneyAustralia

Personalised recommendations