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.
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
Abel, A., Altenkirch, T.: A predicative analysis of structural recursion. Journal of Functional Programming (2000)
Altenkirch, T., Reus, B.: Monadic presentations of lambda-terms using generalized inductive types. In: Computer Science Logic 1999 (1999)
Augustsson, L.: Compiling Pattern Matching. In: Jouannaud, J.-P. (ed.) FPCA 1985. LNCS, vol. 201, pp. 368–381. Springer, Heidelberg (1985)
Augustsson, L.: Cayenne—a language with dependent types. In: ACM International Conference on Functional Programming 1998. ACM, New York (1998)
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
Bellegarde, F., Hook, J.: Substitution: A formal methods case study using monads and transformations. Science of Computer Programming (1995)
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)
Bird, R., de Moor, O.: Algebra of Programming. Prentice Hall, Englewood Cliffs (1997)
Bird, R., Paterson, R.: de Bruijn notation as a nested datatype. Journal of Functional Programming 9(1), 77–92 (1999)
Brady, E.: Practical Implementation of a Dependently Typed Functional Programming Language. PhD thesis, University of Durham (2005)
L’Équipe, C.: The Coq Proof Assistant Reference Manual (2001), http://pauillac.inria.fr/coq/doc/main.html
Coquand, C., Coquand, T.: Structured Type Theory. In: Workshop on Logical Frameworks and Metalanguages (1999)
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)
de Bruijn, N.G.: Lambda Calculus notation with nameless dummies: a tool for automatic formula manipulation. Indagationes Mathematicæ 34, 381–392 (1972)
Dybjer, P.: Inductive Sets and Families in Martin-Löf’s Type Theory. In: Huet, G., Plotkin, G. (eds.) Logical Frameworks, CUP (1991)
Fridlender, D., Indrika, M.: Do we need dependent types? Journal of Functional Programming 10(4), 409–415 (2000)
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)
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)
Luo, Z.: Computation and Reasoning: A Type Theory for Computer Science. Oxford University Press, Oxford (1994)
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)
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)
Martin-Löf, P.: A theory of types (manuscript) (1971)
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/
McBride, C.: Faking It (Simulating Dependent Types in Haskell). Journal of Functional Programming 12(4,5), 375–392 (2002) ( Special Issue on Haskell)
McBride, C.: First-Order Unification by Structural Recursion. Journal of Functional Programming 13(6) (2003)
McBride, C.: Epigram (2004), http://www.dur.ac.uk/CARG/epigram
McBride, C., McKinna, J.: The view from the left. Journal of Functional Programming 14(1) (2004)
McBride, F.: Computer Aided Manipulation of Symbols. PhD thesis, Queen’s University of Belfast (1970)
Milner, R., Tofte, M., Harper, R., MacQueen, D.: The Definition of Standard ML, revised edn. MIT Press, Cambridge (1997)
Okasaki, C.: Purely Functional Data Structures. Cambridge University Press, Cambridge (1998)
Okasaki, C.: From Fast Exponentiation to Square Matrices: An Adventure in Types. In: ACM International Conference on Functional Programming 1999 (1999)
Jones, S.P., Hughes, J.: Haskell 1998: A Non-Strict Functional Language (1999), Available from http://www.haskell.org/definition
Jones, S.P., Washburn, G., Weirich, S.: Wobbly types: type inference for generalised algebraic data types (2004) (unpublished)
Prawitz, D.: Natural Deduction—A proof theoretical study. Almquist and Wiksell, Stockholm (1965)
Nordström, B., Petersson, K., Smith, J.: Programming in Martin-Löf’s type theory: an introduction. Oxford University Press, Oxford (1990)
Robinson, A.: A Machine-oriented Logic Based on the Resolution Principle. Journal of the ACM 12, 23–41 (1965)
Turner, D.: Elementary Strong Functional Programming. In: Functional Programming Languages in Education, First International Symposium. LNCS, vol. 1022. Springer, Heidelberg (1995)
Wadler, P.: Views: A way for pattern matching to cohabit with data abstraction. In: Proceedings of POPL 1987. ACM, New York (1987)
Xi, H.: Dependent Types in Practical Programming. PhD thesis, Department of Mathematical Sciences, Carnegie Mellon University (1998)
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)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights 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)