Abstract
Type classes are one of Haskell's most popular features and extend its type system with ad-hoc polymorphism. Since their conception, there were useful features that could not be offered because of the desire to offer two correctness properties: coherence and global uniqueness of instances. Coherence essentially guarantees that program semantics are independent from type-checker internals. Global uniqueness of instances is relied upon by libraries for enforcing, for example, that a single order relation is used for all manipulations of an ordered binary tree.
The features that could not be offered include explicit dictionary application and local instances, which would be highly useful in practice. In this paper, we propose a new design for offering explicit dictionary application, without compromising coherence and global uniqueness. We introduce a novel criterion based on GHC's type argument roles to decide when a dictionary application is safe with respect to global uniqueness of instances. We preserve coherence by detecting potential sources of incoherence, and prove it formally. Moreover, our solution makes it possible to use local dictionaries. In addition to developing our ideas formally, we have implemented a working prototype in GHC.
- Baldur Blöndal, Andres Löh, and Ryan Scott. 2018. Deriving Via: or, How to Turn Hand-Written Instances into an Anti-Pattern (Haskell ’18). Google Scholar
Digital Library
- Edwin Brady. 2018. The Idris Tutorial, Interfaces. http://docs. idris-lang.org/en/latest/tutorial/interfaces.htmlGoogle Scholar
- Joachim Breitner, Richard A. Eisenberg, Simon Peyton Jones, and Stephanie Weirich. 2014. Safe Zero-cost Coercions for Haskell (ICFP ’14). Google Scholar
Digital Library
- Manuel M. T. Chakravarty, Gabriele Keller, and Simon Peyton Jones. 2005. Associated Type Synonyms (ICFP ’05). Google Scholar
Digital Library
- Manuel M. T. Chakravarty, Gabriele Keller, Simon Peyton Jones, and Simon Marlow. 2005. Associated Types with Class (POPL ’05). Google Scholar
Digital Library
- Dominique Devriese and Frank Piessens. 2011. On the bright side of type classes: instance arguments in Agda (ICFP ’11). Google Scholar
Digital Library
- Atze Dijkstra and Doaitse S. Swierstra. 2005. Making Implicit Parameters Explicit. Technical Report UU-CS-2005-032. Universiteit Utrecht.Google Scholar
- Richard A. Eisenberg, Stephanie Weirich, and Hamidhasan G. Ahmed. 2016. Visible Type Application (ESOP ’16), Vol. 9632.Google Scholar
- Mark P. Jones. 1992. Qualified Types: Theory and Practice. Ph.D. Dissertation. Oxford University. Google Scholar
Digital Library
- Wolfram Kahl and Jan Scheffczyk. 2001. Named Instances for Haskell Type Classes (Haskell ’01).Google Scholar
- Oleg Kiselyov and Chung-chieh Shan. 2004. Functional pearl: implicit configurations–or, type classes reflect the values of types (Haskell ’04). Google Scholar
Digital Library
- Bruno C.d.S. Oliveira, Adriaan Moors, and Martin Odersky. 2010. Type Classes As Objects and Implicits (OOPSLA ’10). Google Scholar
Digital Library
- Bruno C.d.S. Oliveira, Tom Schrijvers, Wontae Choi, Wonchan Lee, and Kwangkeun Yi. 2012. The Implicit Calculus: A New Foundation for Generic Programming (PLDI ’12). Google Scholar
Digital Library
- Simon Peyton Jones, Mark Jones, and Erik Meijer. 1997. Type classes: an exploration of the design space (Haskell ’97).Google Scholar
- Tom Schrijvers, Bruno C.d.S. Oliveira, and Philip Wadler. 2017. Cochis: Deterministic and Coherent Implicits. Technical Report 705. Department of Computer Science, KU Leuven.Google Scholar
- Jeremy G. Siek and Andrew Lumsdaine. 2011. A Language for Generic Programming in the Large. Science of Computer Programming 76, 5 (May 2011). Special Issue on Generative Programming and Component Engineering (Selected Papers from GPCE 2004/2005). Google Scholar
Digital Library
- Matthieu Sozeau and Nicolas Oury. 2008. First-Class Type Classes (TPHOLs ’08). Google Scholar
Digital Library
- 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 (September 2011). Google Scholar
Digital Library
- Philip Wadler and Stephen Blott. 1989. How to make ad-hoc polymorphism less ad hoc (POPL ’89). Google Scholar
Digital Library
- Thomas Winant and Dominique Devriese. 2018. Coherent Explicit Dictionary Application for Haskell: Formalisation and Coherence Proof. ArXiv e-prints (July 2018). arXiv: 1807.11267Google Scholar
- Yizhou Zhang, Matthew C. Loring, Guido Salvaneschi, Barbara Liskov, and Andrew C. Myers. 2015. Lightweight, Flexible Object-oriented Generics (PLDI ’15). Google Scholar
Digital Library
Index Terms
Coherent explicit dictionary application for Haskell
Recommendations
Coherent explicit dictionary application for Haskell
Haskell 2018: Proceedings of the 11th ACM SIGPLAN International Symposium on HaskellType classes are one of Haskell's most popular features and extend its type system with ad-hoc polymorphism. Since their conception, there were useful features that could not be offered because of the desire to offer two correctness properties: ...
Polymorphic variants in Haskell
Haskell '06: Proceedings of the 2006 ACM SIGPLAN workshop on HaskellIn languages that support polymorphic variants, a single variant value can be passed to many contexts that accept different sets of constructors. Polymorphic variants can be used in order to introduce extensible algebraic datatypes into functional ...
Haskell session types with (almost) no class
HASKELL '08We describe an implementation of session types in Haskell. Session types statically enforce that client-server communication proceeds according to protocols. They have been added to several concurrent calculi, but few implementations of session types ...







Comments