Abstract
This paper explores an approach for allowing type classes to be optionally declared by programmers, i.e. programmers can overload symbols without declaring their types in type classes.
The type of an overloaded symbol is, if not explicitly defined in a type class, automatically determined from the anti-unification of instance types defined for the symbol in the relevant module.
This depends on a modularization of instance visibility, as well as on a redefinition of Haskell’s ambiguity rule. The paper presents the modifications to Haskell’s module system that are necessary for allowing instances to have a modular scope, based on previous work by the authors. The definition of the type of overloaded symbols as the anti-unification of available instance types and the redefined ambiguity rule are also based on previous works by the authors.
The added flexibility to Haskell-style of overloading is illustrated by defining a type system and by showing how overloaded record fields can be easily allowed with such a type system.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
References
Camarão, C., Ribeiro, R., Figueiredo, L.: Ambiguity and constrained polymorphism. Sci. Comput. Program. 124(1), 1–19 (2016)
Chang, C.C., Keisler, H.J.: Model Theory, 3rd edn. Dover Books on Mathematics, New York (2012)
Chakravarty, M.M.T., Keller, G., Jones, S.P.: Associated type synonyms. In: Proceedings of the Tenth ACM SIGPLAN International Conference on Functional Programming, ICFP 2005, pp. 241–253 (2005)
Chen, S., Erwig, M.: Principal type inference for GADTs. In: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, pp. 416–428 (2016)
Eisenberg, R.A., Stolarek, J.: Promoting functions to type families in Haskell. In: Proceedings of the 2014 ACM SIGPLAN Symposium on Haskell, Haskell 2014, pp. 95–106 (2014)
Eisenberg, R.A., Vytiniotis, D., Jones, S.P., Weirich, S.: Closed type families with overlapping equations. In: Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2014, pp. 671–683 (2014)
Eisenberg, R.A., Weirich, S.: Dependently typed programming with singletons. In: Proceedings of the 2012 ACM Haskell Symposium, Haskell 2012, pp. 117–130 (2012)
Glasgow Haskell Compiler. http://www.haskell.org/ghc/
Hallgren, T.: Fun with functional dependencies. In: Proceedings of the Joint CS/CE Winter Meeting (2000)
Jones, M.P., Diatchki, I.S.: Language and program design for functional dependencies. In: Proceedings of the First ACM SIGPLAN Symposium on Haskell, Haskell 2008, pp. 87–98 (2008)
Kiselyov, O., Lämmel, R., Schupke, K.: Strongly typed heterogeneous collections. In: Nilsson, H. (ed.) Proceedings of the ACM SIGPLAN Workshop on Haskell, Haskell 2004, pp. 96–107 (2004)
Lindley, S., McBride, C.: Hasochism: the pleasure and pain of dependently typed Haskell programming. In: Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell, Haskell 2013, pp. 81–92 (2013)
Silva, M., Camarão, C., Controlling the scope of instances in Haskell. In: Proceedings of SBLP 2011, pp. 29–30 (2011)
Jones, M.: Qualified types: theory and practice. Ph.D. thesis, Distinguished Dissertations in Computer Science. Cambridge Univ. Press (1994)
Snoyman, M.: Developing Web Applications with Haskell and Yesod. O’Reilly Media Inc., California (2012)
Plotkin, G.D.: A note on inductive generalisation. Mach. Intell. 5(1), 153–163 (1970)
Plotkin, G.D.: A further note on inductive generalisation. Mach. Intell. 6, 101 (1971)
Ribeiro, R., Camarão, C., Figueiredo, L., Vasconcellos, C.: Optional Type Classes for Haskell – On-line Repository (2016). https://github.com/rodrigogribeiro/mptc
Stuckey, P., Sulzmann, M.: A theory of overloading. ACM Trans. Program. Lang. Syst. 27(6), 1216–1269 (2005)
Yorgey, B.A., Weirich, S., Cretin, J., Jones, S.P., Vytiniotis, D., Magalhães, J.P.: Giving Haskell a promotion. In: Proceedings of the 8th ACM SIGPLAN Workshop on Types in Language Design and Implementation, TLDI 2012, pp. 53–66 (2012)
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
Ribeiro, R., Camarão, C., Figueiredo, L., Vasconcellos, C. (2016). Optional Type Classes for Haskell. In: Castor, F., Liu, Y. (eds) Programming Languages. SBLP 2016. Lecture Notes in Computer Science(), vol 9889. Springer, Cham. https://doi.org/10.1007/978-3-319-45279-1_9
Download citation
DOI: https://doi.org/10.1007/978-3-319-45279-1_9
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-45278-4
Online ISBN: 978-3-319-45279-1
eBook Packages: Computer ScienceComputer Science (R0)