Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.1145/3331545.3342596acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Bidirectional type class instances

Published: 08 August 2019 Publication History

Abstract

GADTs were introduced in Haskell’s eco-system more than a decade ago, but their interaction with several mainstream features such as type classes and functional dependencies has a lot of room for improvement. More specifically, for some GADTs it can be surprisingly difficult to provide an instance for even the simplest of type classes.
In this paper we identify the source of this shortcoming and address it by introducing a conservative extension to Haskell’s type classes: Bidirectional Type Class Instances. In essence, under our interpretation class instances correspond to logical bi-implications, in contrast to their traditional unidirectional interpretation.
We present a fully-fledged design of bidirectional instances, covering the specification of typing and elaboration into System FC, as well as an algorithm for type inference and elaboration. We provide a proof-of-concept implementation of our algorithm, and revisit the meta-theory of type classes in the presence of our extension.

References

[1]
Henk Barendregt. 1981. The Lambda Calculus: its Syntax and Semantics, volume 103 of Studies in Logic and the Foundations of Mathematics.
[2]
Gert-Jan Bottu, Georgios Karachalias, Tom Schrijvers, Bruno C. d. S. Oliveira, and Philip Wadler. 2017. Quantified Class Constraints. In Haskell 2017.
[3]
Gert-Jan Bottu, Ningning Xie, Klara Marntirosian, and Tom Schrijvers. 2019. Coherence of Type Class Resolution. Proc. ACM Program. Lang. (2019). Accepted.
[4]
Manuel M. T. Chakravarty, Gabriele Keller, and Simon Peyton Jones. 2005a. Associated Type Synonyms. SIGPLAN Not. 40, 9 (2005), 241–253.
[5]
Manuel M. T. Chakravarty, Gabriele Keller, Simon Peyton Jones, and Simon Marlow. 2005b. Associated Types with Class. In POPL ’05. ACM, 1–13.
[6]
Luis Damas and Robin Milner. 1982. Principal Type-schemes for Functional Programs. In POPL ’82. ACM, 207–212.
[7]
Richard A. Eisenberg, Dimitrios Vytiniotis, Simon Peyton Jones, and Stephanie Weirich. 2014. Closed Type Families with Overlapping Equations. In POPL ’14.
[8]
Jean-Yves Girard. 1972. Interprétation fonctionelle et élimination des coupures de l’arithmétique d’ordre supérieur. Ph.D. Dissertation.
[9]
Douglas Gregor, Jaakko Järvi, Jeremy Siek, Bjarne Stroustrup, Gabriel Dos Reis, and Andrew Lumsdaine. 2006. Concepts: Linguistic Support for Generic Programming in C++. SIGPLAN Not. 41, 10 (2006), 291–310.
[10]
Cordelia V. Hall, Kevin Hammond, Simon L. Peyton Jones, and Philip L. Wadler. 1996. Type Classes in Haskell. TOPLAS 18, 2 (March 1996).
[11]
Thomas Hallgren. 2000. Fun with Functional Dependencies. In Proc. of the Joint CS/CE Winter Meeting.
[12]
Fergus Henderson, Thomas Conway, Zoltan Somogyi, David Jeffery, Peter Schachte, Simon Taylor, and Chris Speirs. 1996. The Mercury Language Reference Manual. Technical Report.
[13]
Fritz Henglein. 1993. Type Inference with Polymorphic Recursion. ACM Trans. Program. Lang. Syst. 15, 2 (April 1993), 253–289.
[14]
R. Hindley. 1969. The Principal Type-Scheme of an Object in Combinatory Logic. Trans. Amer. Math. Soc. 146 (1969), 29–60.
[15]
Patricia Johann and Neil Ghani. 2008. Foundations for Structured Programming with GADTs. SIGPLAN Not. 43, 1 (Jan. 2008), 297–308.
[16]
Mark P. Jones. 1992. A theory of qualified types. In ESOP ’92, Bernd KriegBrückner (Ed.). LNCS, Vol. 582. Springer Berlin Heidelberg, 287–306.
[17]
Mark P. Jones. 1995a. Qualified Types: Theory and Practice. Cambridge University Press.
[18]
Mark P. Jones. 1995b. Simplifying and Improving Qualified Types. In FPCA ’95. ACM, 160–169.
[19]
Mark P. Jones. 2000. Type Classes with Functional Dependencies. In Programming Languages and Systems. LNCS, Vol. 1782. Springer.
[20]
Georgios Karachalias and Tom Schrijvers. 2017. Elaboration on Functional Dependencies: Functional Dependencies Are Dead, Long Live Functional Dependencies! SIGPLAN Not. 52, 10 (Sept. 2017), 133–147.
[21]
Robert Kowalski. 1974. Predicate Logic as Programming Language. In Proceedings of IFIP ’74. North Holland, 569–574.
[22]
The Coq development team. 2004. The Coq proof assistant reference manual. LogiCal Project. http://coq.inria.fr Version 8.0.
[23]
J. Garrett Morris. 2014. A Simple Semantics for Haskell Overloading. SIG-PLAN Not. 49, 12 (2014), 107–118.
[24]
J. Garrett Morris and Richard A. Eisenberg. 2017. Constrained Type Families. In ICFP ’17. ACM.
[25]
J. Garrett Morris and Mark P. Jones. 2010. Instance Chains: Type Class Programming Without Overlapping Instances. In ICFP ’10. ACM.
[26]
Giuseppe Peano. 1889. Arithmetices principia: nova methodo exposita. Fratres Bocca. https://books.google.be/books?id=UUFtAAAAMAAJ
[27]
Simon Peyton Jones. 2003. Haskell 98 Language and Libraries: The Revised Report. Cambridge University Press.
[28]
Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Geoffrey Washburn. 2006. Simple Unification-based Type Inference for GADTs. SIGPLAN Not. 41, 9 (2006), 50–61.
[29]
Norman Ramsey, João Dias, and Simon Peyton Jones. 2010. Hoopl: A Modular, Reusable Library for Dataflow Analysis and Transformation. SIGPLAN Not. 45, 11 (Sept. 2010), 121–134.
[30]
John C. Reynolds. 1974. Towards a Theory of Type Structure. In Programming Symposium, Proceedings Colloque Sur La Programmation. 408–423.
[31]
John C. Reynolds. 1983a. Types, Abstraction, and Parametric Polymorphism. In Information Processing 83, R.E.A. Mason (Ed.). 513–523.
[32]
John C. Reynolds. 1983b. Types, abstraction and parametric polymorphism. (1983).
[33]
Tom Schrijvers, Simon Peyton Jones, Manuel Chakravarty, and Martin Sulzmann. 2008. Type Checking with Open Type Functions. In ICFP ’08. ACM, 51–62.
[34]
M. Sulzmann, M. M. T. Chakravarty, S. Peyton Jones, and K. Donnelly. 2007a. System F with Type Equality Coercions. In TLDI ’07. ACM.
[35]
Martin Sulzmann, Gregory J. Duck, Simon Peyton-Jones, and Peter J. Stuckey. 2007b. Understanding Functional Dependencies via Constraint Handling Rules. J. Funct. Program. 17, 1 (2007), 83–129.
[36]
Dimitrios Vytiniotis, Simon Peyton jones, Tom Schrijvers, and Martin Sulzmann. 2011. Outsidein(x) Modular Type Inference with Local Assumptions. J. Funct. Program. 21, 4-5 (Sept. 2011), 333–412.
[37]
P. Wadler and S. Blott. 1989. How to Make Ad-hoc Polymorphism Less Ad Hoc. In POPL ’89. ACM, 60–76.
[38]
Brent A. Yorgey, Stephanie Weirich, Julien Cretin, Simon Peyton Jones, Dimitrios Vytiniotis, and José Pedro Magalhães. 2012. Giving Haskell a Promotion. In TLDI ’12. ACM, 53–66.

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
Haskell 2019: Proceedings of the 12th ACM SIGPLAN International Symposium on Haskell
August 2019
175 pages
ISBN:9781450368131
DOI:10.1145/3331545
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 08 August 2019

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Haskell
  2. elaboration
  3. type classes
  4. type inference

Qualifiers

  • Research-article

Conference

ICFP '19
Sponsor:

Acceptance Rates

Overall Acceptance Rate 57 of 143 submissions, 40%

Upcoming Conference

ICFP '25
ACM SIGPLAN International Conference on Functional Programming
October 12 - 18, 2025
Singapore , Singapore

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 101
    Total Downloads
  • Downloads (Last 12 months)10
  • Downloads (Last 6 weeks)2
Reflects downloads up to 08 Feb 2025

Other Metrics

Citations

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media