Skip to main content

Epigram: Practical Programming with Dependent Types

  • Conference paper
Advanced Functional Programming

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

Abstract

Find the type error in the following Haskell expression:

if null xs then tail xs else xs

You can’t, of course: this program is obviously nonsense unless you’re a typechecker. The trouble is that only certain computations make sense if the null xs test is True, whilst others make sense if it is False. However, as far as the type system is concerned, the type of the then branch is the type of the else branch is the type of the entire conditional. Statically, the test is irrelevant. Which is odd, because if the test really were irrelevant, we wouldn’t do it. Of course, tail [] doesn’t go wrong—well-typed programs don’t go wrong—so we’d better pick a different word for the way they do go.

Abstraction and application, tupling and projection: these provide the ‘software engineering’ superstructure for programs, and our familiar type systems ensure that these operations are used compatibly. However, sooner or later, most programs inspect data and make a choice—at that point our familiar type systems fall silent. They simply can’t talk about specific data. All this time, we thought our programming was strongly typed, when it was just our software engineering. In order to do better, we need a static language capable of expressing the significance of particular values in legitimizing some computations rather than others. We should not give up on 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 54.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. Abel, A., Altenkirch, T.: A predicative analysis of structural recursion. Journal of Functional Programming (2000)

    Google Scholar 

  2. Altenkirch, T., Reus, B.: Monadic presentations of lambda-terms using generalized inductive types. In: Computer Science Logic 1999 (1999)

    Google Scholar 

  3. Augustsson, L.: Compiling Pattern Matching. In: Jouannaud, J.-P. (ed.) FPCA 1985. LNCS, vol. 201, pp. 368–381. Springer, Heidelberg (1985)

    Chapter  Google Scholar 

  4. Augustsson, L.: Cayenne—a language with dependent types. In: ACM International Conference on Functional Programming 1998. ACM, New York (1998)

    Google Scholar 

  5. Augustsson, L., Carlsson, M.: An exercise in dependent types: A well-typed interpreter (1999), Available at http://www.cs.chalmers.se/~augustss/cayenne/interp.ps

  6. Bellegarde, F., Hook, J.: Substitution: A formal methods case study using monads and transformations. Science of Computer Programming (1995)

    Google Scholar 

  7. Bertot, Y., Castéran, P.: Interactive Theorem Proving and Program Development, Coq’Art: The Calculus of Inductive Constructions. Texts in Theoretical Computer Science. Springer, Heidelberg (2004)

    Google Scholar 

  8. Bird, R., de Moor, O.: Algebra of Programming. Prentice Hall, Englewood Cliffs (1997)

    MATH  Google Scholar 

  9. Bird, R., Paterson, R.: de Bruijn notation as a nested datatype. Journal of Functional Programming 9(1), 77–92 (1999)

    Article  MathSciNet  Google Scholar 

  10. Brady, E.: Practical Implementation of a Dependently Typed Functional Programming Language. PhD thesis, University of Durham (2005)

    Google Scholar 

  11. L’Équipe, C.: The Coq Proof Assistant Reference Manual (2001), http://pauillac.inria.fr/coq/doc/main.html

  12. Coquand, C., Coquand, T.: Structured Type Theory. In: Workshop on Logical Frameworks and Metalanguages (1999)

    Google Scholar 

  13. Coquand, T.: Pattern Matching with Dependent Types. In: Nordström, B., Petersson, K., Plotkin, G. (eds.) Electronic Proceedings of the Third Annual BRA Workshop on Logical Frameworks, Båstad, Sweden (1992)

    Google Scholar 

  14. de Bruijn, N.G.: Lambda Calculus notation with nameless dummies: a tool for automatic formula manipulation. Indagationes Mathematicæ 34, 381–392 (1972)

    Article  Google Scholar 

  15. Dybjer, P.: Inductive Sets and Families in Martin-Löf’s Type Theory. In: Huet, G., Plotkin, G. (eds.) Logical Frameworks, CUP (1991)

    Google Scholar 

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

    Article  Google Scholar 

  17. Giménez, E.: Codifying guarded definitions with recursive schemes. In: Dybjer, P., Nordström, B., Smith, J. (eds.) Types for Proofs and Programs, 1994. LNCS, vol. 996, pp. 39–59. Springer, Heidelberg (1994)

    Chapter  Google Scholar 

  18. Lämmel, R., Jones, S.P.: Scrap your boilerplate: a practical design pattern for generic programming. ACM SIGPLAN Notices 38(3), 26–37 (2003); Proc. of the ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI 2003)

    Article  Google Scholar 

  19. Luo, Z.: Computation and Reasoning: A Type Theory for Computer Science. Oxford University Press, Oxford (1994)

    MATH  Google Scholar 

  20. Luo, Z., Pollack, R.: LEGO Proof Development System: User’s Manual. Technical Report ECS-LFCS-92-211, Laboratory for Foundations of Computer Science, University of Edinburgh (1992)

    Google Scholar 

  21. Magnusson, L., Nordström, B.: The ALF proof editor and its proof engine. In: Barendregt, H., Nipkow, T. (eds.) Types for Proofs and Programs. LNCS, vol. 806. Springer, Heidelberg (1994); Selected papers from the Int. Workshop TYPES 1993, Nijmegen (May 1993)

    Chapter  Google Scholar 

  22. Martin-Löf, P.: A theory of types (manuscript) (1971)

    Google Scholar 

  23. McBride, C.: Dependently Typed Functional Programs and their Proofs. PhD thesis, University of Edinburgh (1999), Available from http://www.lfcs.informatics.ed.ac.uk/reports/00/ECS-LFCS-00-419/

  24. McBride, C.: Faking It (Simulating Dependent Types in Haskell). Journal of Functional Programming 12(4,5), 375–392 (2002) ( Special Issue on Haskell)

    Article  MathSciNet  Google Scholar 

  25. McBride, C.: First-Order Unification by Structural Recursion. Journal of Functional Programming 13(6) (2003)

    Google Scholar 

  26. McBride, C.: Epigram (2004), http://www.dur.ac.uk/CARG/epigram

  27. McBride, C., McKinna, J.: The view from the left. Journal of Functional Programming 14(1) (2004)

    Google Scholar 

  28. McBride, F.: Computer Aided Manipulation of Symbols. PhD thesis, Queen’s University of Belfast (1970)

    Google Scholar 

  29. Milner, R., Tofte, M., Harper, R., MacQueen, D.: The Definition of Standard ML, revised edn. MIT Press, Cambridge (1997)

    Book  Google Scholar 

  30. Okasaki, C.: Purely Functional Data Structures. Cambridge University Press, Cambridge (1998)

    Book  Google Scholar 

  31. Okasaki, C.: From Fast Exponentiation to Square Matrices: An Adventure in Types. In: ACM International Conference on Functional Programming 1999 (1999)

    Google Scholar 

  32. Jones, S.P., Hughes, J.: Haskell 1998: A Non-Strict Functional Language (1999), Available from http://www.haskell.org/definition

  33. Jones, S.P., Washburn, G., Weirich, S.: Wobbly types: type inference for generalised algebraic data types (2004) (unpublished)

    Google Scholar 

  34. Prawitz, D.: Natural Deduction—A proof theoretical study. Almquist and Wiksell, Stockholm (1965)

    MATH  Google Scholar 

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

    MATH  Google Scholar 

  36. Robinson, A.: A Machine-oriented Logic Based on the Resolution Principle. Journal of the ACM 12, 23–41 (1965)

    Article  MathSciNet  Google Scholar 

  37. Turner, D.: Elementary Strong Functional Programming. In: Functional Programming Languages in Education, First International Symposium. LNCS, vol. 1022. Springer, Heidelberg (1995)

    Google Scholar 

  38. Wadler, P.: Views: A way for pattern matching to cohabit with data abstraction. In: Proceedings of POPL 1987. ACM, New York (1987)

    Google Scholar 

  39. Xi, H.: Dependent Types in Practical Programming. PhD thesis, Department of Mathematical Sciences, Carnegie Mellon University (1998)

    Google Scholar 

  40. Xi, H., Pfenning, F.: Eliminating array bound checking through dependent types. In: Proceedings of the Conference on Programming Language Design and Implementation (PLDI 1998). ACM Press, New York (1998)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2005 Springer-Verlag Berlin Heidelberg

About this paper

Cite this paper

McBride, C. (2005). Epigram: Practical Programming with Dependent Types. In: Vene, V., Uustalu, T. (eds) Advanced Functional Programming. Lecture Notes in Computer Science, vol 3622. Springer, Berlin, Heidelberg. https://doi.org/10.1007/11546382_3

Download citation

  • DOI: https://doi.org/10.1007/11546382_3

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-540-28540-3

  • Online ISBN: 978-3-540-31872-9

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics