skip to main content
10.1145/3242744.3242746acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Deriving via: or, how to turn hand-written instances into an anti-pattern

Published:17 September 2018Publication History

ABSTRACT

Haskell's deriving construct is a cheap and cheerful way to quickly generate instances of type classes that follow common patterns. But at present, there is only a subset of such type class patterns that deriving supports, and if a particular class lies outside of this subset, then one cannot derive it at all, with no alternative except for laboriously declaring the instances by hand.

To overcome this deficit, we introduce Deriving Via, an extension to deriving that enables programmers to compose instances from named programming patterns, thereby turning deriving into a high-level domain-specific language for defining instances. Deriving Via leverages newtypes---an already familiar tool of the Haskell trade---to declare recurring patterns in a way that both feels natural and allows a high degree of abstraction.

References

  1. Joachim Breitner, Richard A. Eisenberg, Simon Peyton Jones, and Stephanie Weirich. 2014. Safe Zero-cost Coercions for Haskell. In Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming (ICFP ’14) . ACM, New York, NY, USA, 189– 202. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Manuel M. T. Chakravarty, Gabriele Keller, and Simon Peyton Jones. 2005. Associated Type Synonyms. In Proceedings of the Tenth ACM SIGPLAN International Conference on Functional Programming (ICFP ’05) . ACM, New York, NY, USA, 241–253. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Koen Claessen and John Hughes. 2000. QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs. In Proceedings of the Fifth ACM SIGPLAN International Conference on Functional Programming (ICFP ’00) . ACM, New York, NY, USA, 268–279. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Edsko de Vries and Andres Löh. 2014. True Sums of Products. In Proceedings of the 10th ACM SIGPLAN Workshop on Generic Programming (WGP ’14) . ACM, New York, NY, USA, 83–94. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Larry Diehl, Denis Firsov, and Aaron Stump. 2018. Generic Zero-cost Reuse for Dependent Types. Proc. ACM Program. Lang. 2, ICFP, Article 104 (July 2018), 30 pages. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Atze Dijkstra and S. Doaitse Swierstra. 2005. Making implicit parameters explicit . Technical Report UU-CS-2005-032. Department of Information and Computing Sciences, Utrecht University. http: //www.cs.uu.nl/research/techreps/repo/CS-2005/2005-032.pdfGoogle ScholarGoogle Scholar
  7. Richard A. Eisenberg, Stephanie Weirich, and Hamidhasan G. Ahmed. 2016. Visible Type Application. In Proceedings of the 25th European Symposium on Programming Languages and Systems - Volume 9632 . Springer-Verlag New York, Inc., New York, NY, USA, 229–254.Google ScholarGoogle Scholar
  8. Conal Elliott. 2009. applicative-numbers: Applicative-based numeric instances. https://hackage.haskell.org/package/applicative-numbersGoogle ScholarGoogle Scholar
  9. Jeremy Gibbons and Bruno c. d. s. Oliveira. 2009. The Essence of the Iterator Pattern. J. Funct. Program. 19, 3-4 (July 2009), 377–402. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Gabriel Gonzalez. 2014. Equational reasoning at scale. http://www. haskellforall.com/2014/07/equational-reasoning-at-scale.htmlGoogle ScholarGoogle Scholar
  11. José Pedro Magalhães, Atze Dijkstra, Johan Jeuring, and Andres Löh. 2010. A Generic Deriving Mechanism for Haskell. In Proceedings of the Third ACM Haskell Symposium on Haskell (Haskell ’10) . ACM, New York, NY, USA, 37–48. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Herbert V. Riedel and David Luposchainsky. 2015. Monad of no return Proposal (MRP): Moving return out of Monad. https://mail.haskell. org/pipermail/libraries/2015-September/026121.htmlGoogle ScholarGoogle Scholar
  13. Brent A. Yorgey, Stephanie Weirich, Julien Cretin, Simon Peyton Jones, Dimitrios Vytiniotis, and José Pedro Magalhães. 2012. Giving Haskell a Promotion. In Proceedings of the 8th ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI ’12) . ACM, New York, NY, USA, 53–66. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Deriving via: or, how to turn hand-written instances into an anti-pattern

      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
      • Published in

        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

        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 the author(s) 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].

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 17 September 2018

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article

        Acceptance Rates

        Overall Acceptance Rate57of143submissions,40%

        Upcoming Conference

        ICFP '24

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader