Abstract
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.
Work partially supported by the Spanish MINECO project CAVI-ART (TIN2013-44742-C4-3-R), Madrid regional project N-GREENS Software-CM (S2013/ICE-2731) and UCM-Santander grants GR3/14-910502, GR3/14-910398.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
Notes
- 1.
Written in actual Erlang as none(), any(), but we omit those () for types.
References
Erlang reference manual user’s guide v 6.4: 7. types and function specifications (2015). http://erlang.org/doc/reference_manual/typespec.html
Armstrong, J.: Programming Erlang: Software for a Concurrent World. The Pragmatic Programmers. Pragmatic Bookshelf (2013)
Carlsson, R.: An introduction to core erlang. In: Proceedings of the PLI 2001 Erlang Workshop. Citeseer (2001)
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)
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 1989
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)
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)
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)
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)
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)
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)
Pierce, B.C.: Programming with intersection types and bounded polymorphism. Technical report (1991)
Reynolds, J.C.: Types, abstraction, and parametric polymorphism. In: Mason, R.E.A. (ed.) Information Processing 83. Elsevier Science Inc. (1983)
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)
Wadler, P.: Theorems for free! In: Proceedings of the Fourth International Conference on Functional Programming Languages and Computer Architecture, pp. 347–359. ACM (1989)
Acknowledgements
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.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2016 Springer International Publishing Switzerland
About this paper
Cite this paper
López-Fraguas, F.J., Montenegro, M., Rodríguez-Hortalá, J. (2016). Polymorphic Types in Erlang Function Specifications. In: Kiselyov, O., King, A. (eds) Functional and Logic Programming. FLOPS 2016. Lecture Notes in Computer Science(), vol 9613. Springer, Cham. https://doi.org/10.1007/978-3-319-29604-3_12
Download citation
DOI: https://doi.org/10.1007/978-3-319-29604-3_12
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-29603-6
Online ISBN: 978-3-319-29604-3
eBook Packages: Computer ScienceComputer Science (R0)