Skip to main content

Generic Programming with Dependent Types

  • Chapter
Generic and Indexed Programming

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 7470))

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 49.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Altenkirch, T., McBride, C.: Generic programming within dependently typed programming. In: Proceedings of the IFIP TC2 Working Conference on Generic Programming (2003)

    Google Scholar 

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

  3. 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)

    MathSciNet  MATH  Google Scholar 

  4. Cardelli, L.: A polymorphic lambda calculus with Type:Type. Research Report 10, DEC Systems Research Center (1986)

    Google Scholar 

  5. 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)

    Chapter  Google Scholar 

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

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

    Chapter  Google Scholar 

  8. 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)

    Google Scholar 

  9. Fridlender, D., Indrika, M.: Do we need dependent types? Journal of Functional Programming 10(4), 409–415 (2000)

    Article  MATH  Google Scholar 

  10. Girard, J.-Y.: Interprétation fonctionelle et élimination des coupures de l’arithmétique d’ordre supérieur. PhD thesis, Université Paris VII (1972)

    Google Scholar 

  11. Harper, R., Pollack, R.: Type checking with universes. Theoretical Computer Science 89, 107–136 (1991)

    Article  MathSciNet  MATH  Google Scholar 

  12. Hinze, R.: Polytypic values possess polykinded types. Science of Computer Programming 43(2-3), 129–159 (2002); MPC Special Issue

    Article  MathSciNet  MATH  Google Scholar 

  13. Hinze, R.: Generics for the masses. Journal of Functional Programming 16(4-5), 451–483 (2006)

    Article  MathSciNet  MATH  Google Scholar 

  14. 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)

    Article  MathSciNet  MATH  Google Scholar 

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

    Chapter  Google Scholar 

  16. Kiselyov, O.: Typed Tagless Final Interpreters. In: Gibbons, J. (ed.) Generic and Indexed Programming. LNCS, vol. 7470, pp. 130–174. Springer, Heidelberg (2012)

    Google Scholar 

  17. Martin-Löf, P.: Intuitionistic Type Theory. Bibliopolis-Napoli (1984)

    Google Scholar 

  18. McBride, C.: Faking it: Simulating dependent types in Haskell. Journal of Functional Programming 12(5), 375–392 (2002)

    Article  MathSciNet  MATH  Google Scholar 

  19. Conor, M., James, M.: The view from the left. Journal of Functional Programming 14(1), 69–111 (2004)

    Article  MathSciNet  MATH  Google Scholar 

  20. 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)

    Google Scholar 

  21. Nordström, B., Petersson, K., Smith, J.: Programming in Martin-Löf’s Type Theory: an introduction. Oxford University Press (1990)

    Google Scholar 

  22. 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)

    Google Scholar 

  23. 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/

    Google Scholar 

  24. 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)

    Google Scholar 

  25. T. Sheard. Putting Curry-Howard to work. In Proceedings of the ACM SIGPLAN 2005 Haskell Workshop. ACM Press, September 2005.

    Google Scholar 

  26. 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)

    Chapter  Google Scholar 

  27. 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)

    Chapter  Google Scholar 

  28. 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)

    Chapter  Google Scholar 

  29. The Coq Development Team. The Coq Proof Assistant Reference Manual, Version 8.1. LogiCal Project (2006), http://coq.inria.fr/V8.1beta/refman/

  30. 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)

    Chapter  Google Scholar 

  31. 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)

    Chapter  Google Scholar 

  32. Verbruggen, W., de Vries, E., Hughes, A.: Formal polytypic programs and proofs. Journal of Functional Programming 20, 213–270 (2010)

    Article  MathSciNet  MATH  Google Scholar 

  33. Weirich, S.: Type-safe run-time polytypic programming. Journal of Functional Programming 16(10), 681–710 (2006)

    Article  MathSciNet  MATH  Google Scholar 

  34. Weirich, S.: RepLib: A library for derivable type classes. In: Haskell Workshop, Portland, OR, USA, pp. 1–12 (September 2006)

    Google Scholar 

  35. Weirich, S.: Generic programming with dependent types: Lectures presented at the Spring School on Generic and Indexed Programming (2010)

    Google Scholar 

  36. Weirich, S., Casinghino, C.: Arity-generic datatype-generic programming. In: PLPV 2010: Proceedings of the 4th Workshop on Programming Languages Meets Program Verification (2010)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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)

Publish with us

Policies and ethics