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.
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 ScholarDigital Library
- 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 Scholar
- 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 Scholar
- Conal Elliott. 2009. applicative-numbers: Applicative-based numeric instances. https://hackage.haskell.org/package/applicative-numbersGoogle Scholar
- 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 ScholarDigital Library
- Gabriel Gonzalez. 2014. Equational reasoning at scale. http://www. haskellforall.com/2014/07/equational-reasoning-at-scale.htmlGoogle Scholar
- 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 ScholarDigital Library
- 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 Scholar
- 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 ScholarDigital Library
Index Terms
- Deriving via: or, how to turn hand-written instances into an anti-pattern
Recommendations
Deriving via: or, how to turn hand-written instances into an anti-pattern
Haskell '18Haskell'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 ...
A generic deriving mechanism for Haskell
Haskell '10: Proceedings of the third ACM Haskell symposium on HaskellHaskell's deriving mechanism supports the automatic generation of instances for a number of functions. The Haskell 98 Report only specifies how to generate instances for the Eq, Ord, Enum, Bounded, Show, and Read classes. The description of how to ...
A generic deriving mechanism for Haskell
HASKELL '10Haskell's deriving mechanism supports the automatic generation of instances for a number of functions. The Haskell 98 Report only specifies how to generate instances for the Eq, Ord, Enum, Bounded, Show, and Read classes. The description of how to ...
Comments