Abstract
Free theorems are a charm, allowing the derivation of useful statements about programs from their (polymorphic) types alone. We show how to reap such theorems not only from polymorphism over ordinary types, but also from polymorphism over type constructors restricted by class constraints. Our prime application area is that of monads, which form the probably most popular type constructor class of Haskell. To demonstrate the broader scope, we also deal with a transparent way of introducing difference lists into a program, endowed with a neat and general correctness proof.
Supplemental Material
- L. Birkedal, R.E. Møgelberg, and R.L. Petersen. Domain-theoretical models of parametric polymorphism. Theoretical Computer Science, 388(1--3):152--172, 2007. Google Scholar
Digital Library
- S. Böhme. Free theorems for sublanguages of Haskell. Master's thesis, Technische Universität Dresden, 2007.Google Scholar
- N.A. Danielsson, R.J.M. Hughes, P. Jansson, and J. Gibbons. Fast and loose reasoning is morally correct. In Principles of Programming Languages, Proceedings, pages 206--217. ACM Press, 2006. Google Scholar
Digital Library
- L. Fegaras and T. Sheard. Revisiting catamorphisms over datatypes with embedded functions (or, Programs from outer space). In Principles of Programming Languages, Proceedings, pages 284--294. ACM Press, 1996. Google Scholar
Digital Library
- A. Filinski. On the relations between monadic semantics. Theoretical Computer Science, 375(1-3):41--75, 2007. Google Scholar
Digital Library
- A. Filinski and K. Støvring. Inductive reasoning about effectful data types. In International Conference on Functional Programming, Proceedings, pages 97--110. ACM Press, 2007. Google Scholar
Digital Library
- A. Gill, J. Launchbury, and S.L. Peyton Jones. A short cut to deforestation. In Functional Programming Languages and Computer Architecture, Proceedings, pages 223--232. ACM Press, 1993. Google Scholar
Digital Library
- R.J.M. Hughes. A novel representation of lists and its application to the function "reverse". Information Processing Letters, 22(3):141--144, 1986. Google Scholar
Digital Library
- G. Hutton and D. Fulger. Reasoning about effects: Seeing the wood through the trees. In Trends in Functional Programming, Draft Proceedings, 2008.Google Scholar
- P. Johann and J. Voigtländer. Free theorems in the presence of seq. In Principles of Programming Languages, Proceedings, pages 99--110. ACM Press, 2004. Google Scholar
Digital Library
- J. Kuan. Metatheorems about Convertibility in Typed Lambda Calculi: Applications to CPS Transform and "Free Theorems". PhD thesis, Massachusetts Institute of Technology, 1997.Google Scholar
- J. Launchbury and S.L. Peyton Jones. State in Haskell. Lisp and Symbolic Computation, 8(4):293--341, 1995. Google Scholar
Digital Library
- S. Liang, P. Hudak, and M.P. Jones. Monad transformers and modular interpreters. In Principles of Programming Languages, Proceedings, pages 333--343. ACM Press, 1995. Google Scholar
Digital Library
- J.C. Mitchell and A.R. Meyer. Second--order logical relations (Extended abstract). In Logic of Programs, Proceedings, volume 193 of LNCS, pages 225--236. Springer--Verlag, 1985. Google Scholar
Digital Library
- E. Moggi. Notions of computation and monads. Information and Computation, 93(1):55--92, 1991. Google Scholar
Digital Library
- A. Nanevski, G. Morrisett, A. Shinnar, P. Govereau, and L. Birkedal. Ynot: Dependent types for imperative programs. In International Conference on Functional Programming, Proceedings, pages 229--240. ACM Press, 2008. Google Scholar
Digital Library
- S.L. Peyton Jones and P. Wadler. Imperative functional programming. In Principles of Programming Languages, Proceedings, pages 71--84. ACM Press, 1993. Google Scholar
Digital Library
- J.C. Reynolds. Types, abstraction and parametric polymorphism. In Information Processing, Proceedings, pages 513--523. Elsevier, 1983.Google Scholar
- F. Stenger and J. Voigtländer. Parametricity for Haskell with imprecise error semantics. In Typed Lambda Calculi and Applications, Proceedings, volume 5608 of LNCS, pages 294--308. Springer-Verlag, 2009. Google Scholar
Digital Library
- W. Swierstra. Data types à la carte. Journal of Functional Programming, 18(4):423--436, 2008. Google Scholar
Digital Library
- W. Swierstra and T. Altenkirch. Beauty in the beast -- A functional semantics for the awkward squad. In Haskell Workshop, Proceedings, pages 25--36. ACM Press, 2007. Google Scholar
Digital Library
- I. Takeuti. The theory of parametricity in lambda cube. Manuscript, 2001.Google Scholar
- J. Voigtländer. Concatenate, reverse and map vanish for free. In International Conference on Functional Programming, Proceedings, pages 14--25. ACM Press, 2002. Google Scholar
Digital Library
- J. Voigtländer. Asymptotic improvement of computations over free monads. In Mathematics of Program Construction, Proceedings, volume 5133 of LNCS, pages 388--403. Springer-Verlag, 2008a. Google Scholar
Digital Library
- J. Voigtländer. Much ado about two: A pearl on parallel prefix computation. In Principles of Programming Languages, Proceedings, pages 29--35. ACM Press, 2008b. Google Scholar
Digital Library
- J. Voigtländer. Bidirectionalization for free! In Principles of Programming Languages, Proceedings, pages 165--176. ACM Press, 2009. Google Scholar
Digital Library
- D. Vytiniotis and S. Weirich. Type-safe cast does no harm: Syntactic parametricity for F-omega and beyond. Manuscript, 2009.Google Scholar
- P. Wadler. Theorems for free! In Functional Programming Languages and Computer Architecture, Proceedings, pages 347--359. ACM Press, 1989. Google Scholar
Digital Library
- P. Wadler. The essence of functional programming (Invited talk). In Principles of Programming Languages, Proceedings, pages 1--14. ACM Press, 1992. Google Scholar
Digital Library
- P. Wadler and S. Blott. How to make ad-hoc polymorphism less ad hoc. In Principles of Programming Languages, Proceedings, pages 60--76. ACM Press, 1989. Google Scholar
Digital Library
Index Terms
Free theorems involving type constructor classes: functional pearl
Recommendations
A relationally parametric model of dependent type theory
POPL '14: Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming LanguagesReynolds' theory of relational parametricity captures the invariance of polymorphically typed programs under change of data representation. Reynolds' original work exploited the typing discipline of the polymorphically typed lambda-calculus System F, ...
Free theorems involving type constructor classes: functional pearl
ICFP '09: Proceedings of the 14th ACM SIGPLAN international conference on Functional programmingFree theorems are a charm, allowing the derivation of useful statements about programs from their (polymorphic) types alone. We show how to reap such theorems not only from polymorphism over ordinary types, but also from polymorphism over type ...
A relationally parametric model of dependent type theory
POPL '14Reynolds' theory of relational parametricity captures the invariance of polymorphically typed programs under change of data representation. Reynolds' original work exploited the typing discipline of the polymorphically typed lambda-calculus System F, ...







Comments