Generic Programming with Multiple Parameters

  • José Pedro Magalhães
Part of the Lecture Notes in Computer Science book series (LNCS, volume 8475)

Abstract

Generic programming, a form of abstraction in programming languages that serves to reduce code duplication by exploiting the regular structure of algebraic datatypes, has been present in the Haskell language in different forms for many years. Lately, a library for generic deriving has been given native support in the compiler, allowing programmers to write functions such as fmap that abstract over one datatype parameter generically. The power of this approach is limited to dealing with one parameter per datatype, however. In this paper, we lift this restriction by providing a generalisation of generic deriving that supports multiple parameters, making essential use of datatype promotion and kind polymorphism. We show example encodings of datatypes, and how to define a map function that operates on multiple parameters simultaneously.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Alimarine, A., Plasmeijer, R.: A generic programming extension for Clean. In: Arts, T., Mohnen, M. (eds.) IFL 2002. LNCS, vol. 2312, pp. 168–185. Springer, Heidelberg (2002)CrossRefGoogle Scholar
  2. 2.
    Backhouse, R., Jansson, P., Jeuring, J., Meertens, L.: Generic programming: An introduction. In: Swierstra, S.D., Oliveira, J.N. (eds.) AFP 1998. LNCS, vol. 1608, pp. 28–115. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  3. 3.
    Hinze, R., Jeuring, J., Löh, A.: Comparing approaches to generic programming in Haskell. In: Backhouse, R., Gibbons, J., Hinze, R., Jeuring, J. (eds.) SSDGP 2006. LNCS, vol. 4719, pp. 72–149. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  4. 4.
    Kiselyov, O., Lämmel, R., Schupke, K.: Strongly typed heterogeneous collections. In: Proceedings of the 2004 ACM SIGPLAN Workshop on Haskell, Haskell 2004, pp. 96–107. ACM (2004), doi:10.1145/1017472.1017488Google Scholar
  5. 5.
    Lämmel, R., Peyton Jones, S.: Scrap your boilerplate: a practical design pattern for generic programming. In: Proceedings of the 2003 ACM SIGPLAN International Workshop on Types in Languages Design and Implementation, pp. 26–37. ACM (2003), doi:10.1145/604174.604179Google Scholar
  6. 6.
    Löh, A.: Exploring Generic Haskell. PhD thesis, Universiteit Utrecht (2004), http://igitur-archive.library.uu.nl/dissertations/2004-1130-111344
  7. 7.
    Löh, A., Magalhães, J.P.: Generic programming with indexed functors. In: Proceedings of the 7th ACM SIGPLAN Workshop on Generic Programming, pp. 1–12. ACM (2011), doi:10.1145/2036918.2036920Google Scholar
  8. 8.
    Magalhães, J.P.: Less Is More: Generic Programming Theory and Practice. PhD thesis, Universiteit Utrecht (2012)Google Scholar
  9. 9.
    Magalhães, J.P.: The right kind of generic programming. In: Proceedings of the 8th ACM SIGPLAN Workshop on Generic Programming, WGP 2012, pp. 13–24. ACM, New York (2012) ISBN 978-1-4503-1576-0, doi:10.1145/2364394.2364397Google Scholar
  10. 10.
    Magalhães, J.P., Löh, A.: Generic generic programming (2014), http://dreixel.net/research/pdf/ggp.pdf, Accepted for publication at Practical Aspects of Declarative Languages (PADL 2014)
  11. 11.
    Magalhães, J.P., Dijkstra, A., Jeuring, J., Löh, A.: A generic deriving mechanism for Haskell. In: Proceedings of the 3rd ACM Haskell Symposium on Haskell, pp. 37–48. ACM (2010), doi:10.1145/1863523.1863529Google Scholar
  12. 12.
    Peyton Jones, S. (ed.): Haskell 98, Language and Libraries. The Revised Report. Cambridge University Press (2003), doi:10.1017/S0956796803000315, Journal of Functional Programming Special Issue 13(1)Google Scholar
  13. 13.
    Rodriguez Yakushev, A., Jeuring, J., Jansson, P., Gerdes, A., Kiselyov, O., Oliveira, B.C.D.S.: Comparing libraries for generic programming in Haskell. In: Proceedings of the 1st ACM SIGPLAN Symposium on Haskell, pp. 111–122. ACM (2008), doi:10.1145/1411286.1411301Google Scholar
  14. 14.
    Weirich, S., Casinghino, C.: Arity-generic datatype-generic programming. In: Proceedings of the 4th ACM SIGPLAN Workshop on Programming Languages meets Program Verification, pp. 15–26. ACM (2010), doi:10.1145/1707790.1707799Google Scholar
  15. 15.
    Weirich, S., Hsu, J., Eisenberg, R.A.: System FC with explicit kind equality. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, ICFP 2013, pp. 275–286. ACM (2013), doi:10.1145/2500365.2500599Google Scholar
  16. 16.
    Yorgey, B.A., Weirich, S., Cretin, J., Peyton Jones, S., Vytiniotis, D., Magalhães, J.P.: Giving Haskell a promotion. In: Proceedings of the 8th ACM SIGPLAN Workshop on Types in Language Design and Implementation, pp. 53–66. ACM (2012), doi:10.1145/2103786.2103795Google Scholar

Copyright information

© Springer International Publishing Switzerland 2014

Authors and Affiliations

  • José Pedro Magalhães
    • 1
  1. 1.Department of Computer ScienceUniversity of OxfordOxfordUK

Personalised recommendations