Polymorphic Types in Erlang Function Specifications

  • Francisco J. López-FraguasEmail author
  • Manuel Montenegro
  • Juan Rodríguez-Hortalá
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 9613)


Erlang is a concurrent functional programming language developed by Ericsson, well suited for implementing distributed systems. Although Erlang is dynamically typed, the Dialyzer static analysis tool can be used to extract implicit type information from the programs, both for documentation purposes and for finding errors that will definitively arise at program execution. Dialyzer is based on the notion of success types, that correspond to safe over-approximations for the semantics of expressions. Erlang also supports user given function specifications (or just specs), that are contracts providing more information about the semantics of functions. Function specs are useful not only as documentation, but also can be employed by Dialyzer to improve the precision of the analysis. Even though specs can have a polymorphic shape, in practice Dialyzer is not able to exploit all their potential. One reason for that is that extending the notion of success types to a polymorphic setting is not trivial, and several interpretations are possible. In this work we propose a precise formulation for a novel interpretation of function specs as polymorphic success types, and a program transformation that allows us to apply this new interpretation on the call sites of functions with a declared spec. This results in a significant improvement in the number of definite errors that Dialyzer is able to detect.


Type Variable Simple Type Polymorphic Variable Type Scheme Function Definition 
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.



The authors would like to thank Kostis Sagonas and Stavros Aronis, for many fruitful discussions about Dialyzer and success types, that have been fundamental for developing the intuitions about the meaning of polymorphic success types that is proposed in this paper.


  1. 1.
    Erlang reference manual user’s guide v 6.4: 7. types and function specifications (2015).
  2. 2.
    Armstrong, J.: Programming Erlang: Software for a Concurrent World. The Pragmatic Programmers. Pragmatic Bookshelf (2013)Google Scholar
  3. 3.
    Carlsson, R.: An introduction to core erlang. In: Proceedings of the PLI 2001 Erlang Workshop. Citeseer (2001)Google Scholar
  4. 4.
    Damas, L., Milner, R.: Principal type-schemes for functional programs. In: Proceedings of the 9th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, pp. 207–212. ACM (1982)Google Scholar
  5. 5.
    Gunter, C.A., Mosses, P.D., Scott, D.S.: Semantic domains and denotational semantics. Technical report MS-CIS-89-16, Department of Computer and Information Science, University of Pennsylvania, February 1989Google Scholar
  6. 6.
    Jimenez, M., Lindahl, T., Sagonas, K.: A language for specifying type contracts in erlang and its interaction with success typings. In: Proceedings of the 2007 SIGPLAN Workshop on ERLANG Workshop, pp. 11–17. ACM (2007)Google Scholar
  7. 7.
    Lindahl, T., Sagonas, K.: Detecting software defects in telecom applications through lightweight static analysis: a war story. In: Chin, W.-N. (ed.) APLAS 2004. LNCS, vol. 3302, pp. 91–106. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  8. 8.
    Lindahl, T., Sagonas, K.: Typer: a type annotator of erlang code. In: Proceedings of the 2005 ACM SIGPLAN Workshop on Erlang, pp. 17–25. ACM (2005)Google Scholar
  9. 9.
    Lindahl, T., Sagonas, K.: Practical type inference based on success typings. In: Proceedings of the 8th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming, PPDP 2006, pp. 167–178, New York, NY, USA. ACM (2006)Google Scholar
  10. 10.
    López-Fraguas, F.J., Montenegro, M., Sánchez-Hernández, J.: Polymorphic types in Erlang function specifications (extended version). Technical report TR-3-15, Departamento de Sistemas Informáticos y Computación, Universidad Complutense de Madrid (2015)Google Scholar
  11. 11.
    Marlow, S., Wadler, P.: A practical subtyping system for erlang. In: Proceedings of the Second ACM SIGPLAN International Conference on Functional Programming, ICFP 1997, pp. 136–149, New York, NY, USA. ACM (1997)Google Scholar
  12. 12.
    Pierce, B.C.: Programming with intersection types and bounded polymorphism. Technical report (1991)Google Scholar
  13. 13.
    Reynolds, J.C.: Types, abstraction, and parametric polymorphism. In: Mason, R.E.A. (ed.) Information Processing 83. Elsevier Science Inc. (1983)Google Scholar
  14. 14.
    Sagonas, K.: Using static analysis to detect type errors and concurrency defects in erlang programs. In: Blume, M., Kobayashi, N., Vidal, G. (eds.) FLOPS 2010. LNCS, vol. 6009, pp. 13–18. Springer, Heidelberg (2010)CrossRefGoogle Scholar
  15. 15.
    Wadler, P.: Theorems for free! In: Proceedings of the Fourth International Conference on Functional Programming Languages and Computer Architecture, pp. 347–359. ACM (1989)Google Scholar

Copyright information

© Springer International Publishing Switzerland 2016

Authors and Affiliations

  • Francisco J. López-Fraguas
    • 1
    Email author
  • Manuel Montenegro
    • 1
  • Juan Rodríguez-Hortalá
    • 1
  1. 1.Departamento de Sistemas Informáticos Y ComputaciónUniversidad Complutense de MadridMadridSpain

Personalised recommendations