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.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsPreview
Unable to display preview. Download preview PDF.
References
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)
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)
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)
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.1017488
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.604179
Löh, A.: Exploring Generic Haskell. PhD thesis, Universiteit Utrecht (2004), http://igitur-archive.library.uu.nl/dissertations/2004-1130-111344
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.2036920
Magalhães, J.P.: Less Is More: Generic Programming Theory and Practice. PhD thesis, Universiteit Utrecht (2012)
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.2364397
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)
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.1863529
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)
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.1411301
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.1707799
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.2500599
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.2103795
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2014 Springer International Publishing Switzerland
About this paper
Cite this paper
Magalhães, J.P. (2014). Generic Programming with Multiple Parameters. In: Codish, M., Sumii, E. (eds) Functional and Logic Programming. FLOPS 2014. Lecture Notes in Computer Science, vol 8475. Springer, Cham. https://doi.org/10.1007/978-3-319-07151-0_9
Download citation
DOI: https://doi.org/10.1007/978-3-319-07151-0_9
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-07150-3
Online ISBN: 978-3-319-07151-0
eBook Packages: Computer ScienceComputer Science (R0)