Abstract
Some programs are doubly generic. For example, map is datatype-generic in that many different data structures support a mapping operation. A generic programming language like Generic Haskell can use a single definition to generate map for each type. However, map is also arity-generic because it belongs to a family of related operations that differ in the number of arguments. For lists, this family includes familiar functions from the Haskell standard library (such as repeat, map, and zipWith).
This tutorial explores these forms of genericity individually and together. These two axes are not orthogonal: datatype-generic versions of repeat, map and zipWith have different arities of kind-indexed types. We explore these forms of genericity in the context of the Agda programming language, using the expressiveness of dependent types to capture both forms of genericity in a common framework. Therefore, this tutorial serves as an introduction to dependently typed languages as well as generic programming.
The target audience of this work is someone who is familiar with functional programming languages, such as Haskell or ML, but would like to learn about dependently typed languages. We do not assume prior experience with Agda, type- or arity-generic programming.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Altenkirch, T., McBride, C.: Generic programming within dependently typed programming. In: Proceedings of the IFIP TC2 Working Conference on Generic Programming (2003)
Augustsson, L.: Cayenne a language with dependent types. In: Proceedings of the Third ACM SIGPLAN International Conference on Functional Programming, ICFP 1998, pp. 239–250. ACM, New York (1998) ISBN 1-58113-024-4, http://doi.acm.org/10.1145/289423.289451 , doi:10.1145/289423.289451
Marcin, B., Peter, D., Patrik, J.: Universes for generic programs and proofs in dependent type theory. Nordic Journal of Computing 10(4), 265–289 (2003)
Cardelli, L.: A polymorphic lambda calculus with Type:Type. Research Report 10, DEC Systems Research Center (1986)
Chakravarty, M.M.T., Keller, G., Peyton Jones, S.: Associated type synonyms. In: ICFP 2005: Proceedings of the Tenth ACM SIGPLAN International Conference on Functional Programming, pp. 241–253. ACM, New York (2005)
Chapman, J., Dagand, P.-E., McBride, C., Morris, P.: The gentle art of levitation. In: ICFP 2010, pp. 3–14. ACM, New York (2010) ISBN 978-1-60558-794-3, http://doi.acm.org/10.1145/1863543.1863547
Chlipala, A.: A certified type-preserving compiler from lambda calculus to assembly language. In: PLDI 2007: Proceedings of the 2007 ACM SIGPLAN Conference on Programming Language Design and Implementation, pp. 54–65. ACM, New York (2007)
Clarke, D., Hinze, R., Jeuring, J., Löh, A., de Wit, J.: The Generic Haskell user’s guide. Technical Report UU-CS-2001-26, Utrecht University (2001)
Fridlender, D., Indrika, M.: Do we need dependent types? Journal of Functional Programming 10(4), 409–415 (2000)
Girard, J.-Y.: Interprétation fonctionelle et élimination des coupures de l’arithmétique d’ordre supérieur. PhD thesis, Université Paris VII (1972)
Harper, R., Pollack, R.: Type checking with universes. Theoretical Computer Science 89, 107–136 (1991)
Hinze, R.: Polytypic values possess polykinded types. Science of Computer Programming 43(2-3), 129–159 (2002); MPC Special Issue
Hinze, R.: Generics for the masses. Journal of Functional Programming 16(4-5), 451–483 (2006)
Hinze, R., Löh, A.: Generic programming in 3D. Science of Computer Programming 74(8), 590–628 (2009), doi:10.1016/j.scico.2007.10.006; Special Issue on Mathematics of Program Construction (MPC 2006)
Hoogendijk, P., Backhouse, R.: When do Datatypes Commute? In: Moggi, E., Rosolini, G. (eds.) CTCS 1997. LNCS, vol. 1290, pp. 242–260. Springer, Heidelberg (1997) ISBN 3-540-63455-X, http://dl.acm.org/citation.cfm?id=648335.755730
Kiselyov, O.: Typed Tagless Final Interpreters. In: Gibbons, J. (ed.) Generic and Indexed Programming. LNCS, vol. 7470, pp. 130–174. Springer, Heidelberg (2012)
Martin-Löf, P.: Intuitionistic Type Theory. Bibliopolis-Napoli (1984)
McBride, C.: Faking it: Simulating dependent types in Haskell. Journal of Functional Programming 12(5), 375–392 (2002)
Conor, M., James, M.: The view from the left. Journal of Functional Programming 14(1), 69–111 (2004)
Morris, P., Altenkirch, T., Ghani, N.: Constructing strictly positive families. In: CATS 2007: Proceedings of the Thirteenth Australasian Symposium on Theory of Computing, Darlinghurst, Australia, Australia, pp. 111–121. Australian Computer Society, Inc. (2007)
Nordström, B., Petersson, K., Smith, J.: Programming in Martin-Löf’s Type Theory: an introduction. Oxford University Press (1990)
Norell, U.: Towards a practical programming language based on dependent type theory. PhD thesis, Department of Computer Science and Engineering, Chalmers University of Technology, SE-412 96 Göteborg, Sweden (September 2007)
Peyton Jones, S.L., et al.: The Haskell 98 language and libraries: The revised report. Journal of Functional Programming 13(1), 0–255 (2003), http://www.haskell.org/definition/
Peyton Jones, S.L., Vytiniotis, D., Weirich, S., Washburn, G.: Simple unification-based type inference for GADTs. In: ICFP 2006: Proceedings of the Eleventh ACM SIGPLAN International Conference on Functional Programming, Portland, OR, USA, pp. 50–61 (September 2006)
T. Sheard. Putting Curry-Howard to work. In Proceedings of the ACM SIGPLAN 2005 Haskell Workshop. ACM Press, September 2005.
Sheard, T.: Generic Programming in Ωmega. In: Backhouse, R., Gibbons, J., Hinze, R., Jeuring, J. (eds.) SSDGP 2006. LNCS, vol. 4719, pp. 258–284. Springer, Heidelberg (2007)
Sozeau, M.: Equations: A Dependent Pattern-Matching Compiler. In: Kaufmann, M., Paulson, L.C. (eds.) ITP 2010. LNCS, vol. 6172, pp. 419–434. Springer, Heidelberg (2010)
Strickland, T.S., Tobin-Hochstadt, S., Felleisen, M.: Practical Variable-Arity Polymorphism. In: Castagna, G. (ed.) ESOP 2009. LNCS, vol. 5502, pp. 32–46. Springer, Heidelberg (2009)
The Coq Development Team. The Coq Proof Assistant Reference Manual, Version 8.1. LogiCal Project (2006), http://coq.inria.fr/V8.1beta/refman/
Verbruggen, W., de Vries, E., Hughes, A.: Polytypic programming in Coq. In: WGP 2008: Proceedings of the ACM SIGPLAN Workshop on Generic Programming, pp. 49–60. ACM, New York (2008)
Verbruggen, W., de Vries, E., Hughes, A.: Polytypic properties and proofs in Coq. In: WGP 2009: Proceedings of the 2009 ACM SIGPLAN Workshop on Generic Programming, pp. 1–12. ACM, New York (2009)
Verbruggen, W., de Vries, E., Hughes, A.: Formal polytypic programs and proofs. Journal of Functional Programming 20, 213–270 (2010)
Weirich, S.: Type-safe run-time polytypic programming. Journal of Functional Programming 16(10), 681–710 (2006)
Weirich, S.: RepLib: A library for derivable type classes. In: Haskell Workshop, Portland, OR, USA, pp. 1–12 (September 2006)
Weirich, S.: Generic programming with dependent types: Lectures presented at the Spring School on Generic and Indexed Programming (2010)
Weirich, S., Casinghino, C.: Arity-generic datatype-generic programming. In: PLPV 2010: Proceedings of the 4th Workshop on Programming Languages Meets Program Verification (2010)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2012 Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
Weirich, S., Casinghino, C. (2012). Generic Programming with Dependent Types. In: Gibbons, J. (eds) Generic and Indexed Programming. Lecture Notes in Computer Science, vol 7470. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-32202-0_5
Download citation
DOI: https://doi.org/10.1007/978-3-642-32202-0_5
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-32201-3
Online ISBN: 978-3-642-32202-0
eBook Packages: Computer ScienceComputer Science (R0)