Skip to main content

Optional Type Classes for Haskell

  • Conference paper
  • First Online:
Programming Languages (SBLP 2016)

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 9889))

Included in the following conference series:

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    A generalization is also called a (first-order) anti-unification [2].

  2. 2.

    In [1] it is called delayed closure ambiguity.

References

  1. Camarão, C., Ribeiro, R., Figueiredo, L.: Ambiguity and constrained polymorphism. Sci. Comput. Program. 124(1), 1–19 (2016)

    Article  Google Scholar 

  2. Chang, C.C., Keisler, H.J.: Model Theory, 3rd edn. Dover Books on Mathematics, New York (2012)

    MATH  Google Scholar 

  3. 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)

    Google Scholar 

  4. 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)

    Google Scholar 

  5. 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)

    Google Scholar 

  6. 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)

    Google Scholar 

  7. Eisenberg, R.A., Weirich, S.: Dependently typed programming with singletons. In: Proceedings of the 2012 ACM Haskell Symposium, Haskell 2012, pp. 117–130 (2012)

    Google Scholar 

  8. Glasgow Haskell Compiler. http://www.haskell.org/ghc/

  9. Hallgren, T.: Fun with functional dependencies. In: Proceedings of the Joint CS/CE Winter Meeting (2000)

    Google Scholar 

  10. 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)

    Google Scholar 

  11. 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)

    Google Scholar 

  12. 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)

    Google Scholar 

  13. Silva, M., Camarão, C., Controlling the scope of instances in Haskell. In: Proceedings of SBLP 2011, pp. 29–30 (2011)

    Google Scholar 

  14. Jones, M.: Qualified types: theory and practice. Ph.D. thesis, Distinguished Dissertations in Computer Science. Cambridge Univ. Press (1994)

    Google Scholar 

  15. Snoyman, M.: Developing Web Applications with Haskell and Yesod. O’Reilly Media Inc., California (2012)

    Google Scholar 

  16. Plotkin, G.D.: A note on inductive generalisation. Mach. Intell. 5(1), 153–163 (1970)

    MATH  Google Scholar 

  17. Plotkin, G.D.: A further note on inductive generalisation. Mach. Intell. 6, 101 (1971)

    MathSciNet  MATH  Google Scholar 

  18. Ribeiro, R., Camarão, C., Figueiredo, L., Vasconcellos, C.: Optional Type Classes for Haskell – On-line Repository (2016). https://github.com/rodrigogribeiro/mptc

    Google Scholar 

  19. Stuckey, P., Sulzmann, M.: A theory of overloading. ACM Trans. Program. Lang. Syst. 27(6), 1216–1269 (2005)

    Article  MATH  Google Scholar 

  20. 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)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Lucília Figueiredo .

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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)

Publish with us

Policies and ethics