skip to main content
article

Coherent explicit dictionary application for Haskell

Published:17 September 2018Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. Edwin Brady. 2018. The Idris Tutorial, Interfaces. http://docs. idris-lang.org/en/latest/tutorial/interfaces.htmlGoogle ScholarGoogle Scholar
  3. Joachim Breitner, Richard A. Eisenberg, Simon Peyton Jones, and Stephanie Weirich. 2014. Safe Zero-cost Coercions for Haskell (ICFP ’14). Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Manuel M. T. Chakravarty, Gabriele Keller, and Simon Peyton Jones. 2005. Associated Type Synonyms (ICFP ’05). Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Manuel M. T. Chakravarty, Gabriele Keller, Simon Peyton Jones, and Simon Marlow. 2005. Associated Types with Class (POPL ’05). Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Dominique Devriese and Frank Piessens. 2011. On the bright side of type classes: instance arguments in Agda (ICFP ’11). Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Atze Dijkstra and Doaitse S. Swierstra. 2005. Making Implicit Parameters Explicit. Technical Report UU-CS-2005-032. Universiteit Utrecht.Google ScholarGoogle Scholar
  8. Richard A. Eisenberg, Stephanie Weirich, and Hamidhasan G. Ahmed. 2016. Visible Type Application (ESOP ’16), Vol. 9632.Google ScholarGoogle Scholar
  9. Mark P. Jones. 1992. Qualified Types: Theory and Practice. Ph.D. Dissertation. Oxford University. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Wolfram Kahl and Jan Scheffczyk. 2001. Named Instances for Haskell Type Classes (Haskell ’01).Google ScholarGoogle Scholar
  11. Oleg Kiselyov and Chung-chieh Shan. 2004. Functional pearl: implicit configurations–or, type classes reflect the values of types (Haskell ’04). Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Bruno C.d.S. Oliveira, Adriaan Moors, and Martin Odersky. 2010. Type Classes As Objects and Implicits (OOPSLA ’10). Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. Simon Peyton Jones, Mark Jones, and Erik Meijer. 1997. Type classes: an exploration of the design space (Haskell ’97).Google ScholarGoogle Scholar
  15. 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 ScholarGoogle Scholar
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. Matthieu Sozeau and Nicolas Oury. 2008. First-Class Type Classes (TPHOLs ’08). Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. Philip Wadler and Stephen Blott. 1989. How to make ad-hoc polymorphism less ad hoc (POPL ’89). Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Thomas Winant and Dominique Devriese. 2018. Coherent Explicit Dictionary Application for Haskell: Formalisation and Coherence Proof. ArXiv e-prints (July 2018). arXiv: 1807.11267Google ScholarGoogle Scholar
  21. Yizhou Zhang, Matthew C. Loring, Guido Salvaneschi, Barbara Liskov, and Andrew C. Myers. 2015. Lightweight, Flexible Object-oriented Generics (PLDI ’15). Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Coherent explicit dictionary application for Haskell

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      • Published in

        cover image ACM SIGPLAN Notices
        ACM SIGPLAN Notices  Volume 53, Issue 7
        Haskell '18
        July 2018
        185 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/3299711
        Issue’s Table of Contents
        • cover image ACM Conferences
          Haskell 2018: Proceedings of the 11th ACM SIGPLAN International Symposium on Haskell
          September 2018
          185 pages
          ISBN:9781450358354
          DOI:10.1145/3242744

        Copyright © 2018 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 17 September 2018

        Check for updates

        Qualifiers

        • article

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!