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 2018 Publication 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.
[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.
[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.
[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.
[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.
[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.pdf
[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.
[8]
Conal Elliott. 2009. applicative-numbers: Applicative-based numeric instances. https://hackage.haskell.org/package/applicative-numbers
[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.
[10]
Gabriel Gonzalez. 2014. Equational reasoning at scale. http://www. haskellforall.com/2014/07/equational-reasoning-at-scale.html
[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.
[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.html
[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.

Cited By

View all
  • (2020)Faster coroutine pipelines: A reconstructionJournal of Functional Programming10.1017/S095679682000019230Online publication date: 3-Aug-2020
  • (2020)Leveraging the Information Contained in Theory PresentationsIntelligent Computer Mathematics10.1007/978-3-030-53518-6_4(55-70)Online publication date: 17-Jul-2020
  • (2019)A language feature to unbundle data at will (short paper)Proceedings of the 18th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences10.1145/3357765.3359523(14-19)Online publication date: 21-Oct-2019
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

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
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].

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 17 September 2018

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Haskell
  2. deriving
  3. functional programming
  4. instances
  5. type classes

Qualifiers

  • Research-article

Conference

ICFP '18
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

  • Downloads (Last 12 months)7
  • Downloads (Last 6 weeks)0
Reflects downloads up to 25 Feb 2025

Other Metrics

Citations

Cited By

View all
  • (2020)Faster coroutine pipelines: A reconstructionJournal of Functional Programming10.1017/S095679682000019230Online publication date: 3-Aug-2020
  • (2020)Leveraging the Information Contained in Theory PresentationsIntelligent Computer Mathematics10.1007/978-3-030-53518-6_4(55-70)Online publication date: 17-Jul-2020
  • (2019)A language feature to unbundle data at will (short paper)Proceedings of the 18th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences10.1145/3357765.3359523(14-19)Online publication date: 21-Oct-2019
  • (2019)A role for dependent types in HaskellProceedings of the ACM on Programming Languages10.1145/33417053:ICFP(1-29)Online publication date: 26-Jul-2019
  • (2019)Modular effects in Haskell through effect polymorphism and explicit dictionary applications: a new approach and the μVeriFast verifier as a case studyProceedings of the 12th ACM SIGPLAN International Symposium on Haskell10.1145/3331545.3342589(1-14)Online publication date: 8-Aug-2019
  • (2018)Coherent explicit dictionary application for HaskellACM SIGPLAN Notices10.1145/3299711.324275253:7(81-93)Online publication date: 17-Sep-2018
  • (2018)Improving typeclass relations by being openACM SIGPLAN Notices10.1145/3299711.324275153:7(68-80)Online publication date: 17-Sep-2018
  • (2018)Coherent explicit dictionary application for HaskellProceedings of the 11th ACM SIGPLAN International Symposium on Haskell10.1145/3242744.3242752(81-93)Online publication date: 17-Sep-2018
  • (2018)Improving typeclass relations by being openProceedings of the 11th ACM SIGPLAN International Symposium on Haskell10.1145/3242744.3242751(68-80)Online publication date: 17-Sep-2018
  • (2019)Working with source pluginsProceedings of the 12th ACM SIGPLAN International Symposium on Haskell10.1145/3331545.3342599(85-97)Online publication date: 8-Aug-2019

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