skip to main content
research-article

Free theorems involving type constructor classes: functional pearl

Published:31 August 2009Publication History
Skip Abstract Section

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.

Skip Supplemental Material Section

Supplemental Material

freetheoremsinvolvingtypeconstructorclassesonvimeo.mp4

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. S. Böhme. Free theorems for sublanguages of Haskell. Master's thesis, Technische Universität Dresden, 2007.Google ScholarGoogle Scholar
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. A. Filinski. On the relations between monadic semantics. Theoretical Computer Science, 375(1-3):41--75, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. G. Hutton and D. Fulger. Reasoning about effects: Seeing the wood through the trees. In Trends in Functional Programming, Draft Proceedings, 2008.Google ScholarGoogle Scholar
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. J. Kuan. Metatheorems about Convertibility in Typed Lambda Calculi: Applications to CPS Transform and "Free Theorems". PhD thesis, Massachusetts Institute of Technology, 1997.Google ScholarGoogle Scholar
  12. J. Launchbury and S.L. Peyton Jones. State in Haskell. Lisp and Symbolic Computation, 8(4):293--341, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. E. Moggi. Notions of computation and monads. Information and Computation, 93(1):55--92, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. S.L. Peyton Jones and P. Wadler. Imperative functional programming. In Principles of Programming Languages, Proceedings, pages 71--84. ACM Press, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. J.C. Reynolds. Types, abstraction and parametric polymorphism. In Information Processing, Proceedings, pages 513--523. Elsevier, 1983.Google ScholarGoogle Scholar
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. W. Swierstra. Data types à la carte. Journal of Functional Programming, 18(4):423--436, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. I. Takeuti. The theory of parametricity in lambda cube. Manuscript, 2001.Google ScholarGoogle Scholar
  23. J. Voigtländer. Concatenate, reverse and map vanish for free. In International Conference on Functional Programming, Proceedings, pages 14--25. ACM Press, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  25. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  26. J. Voigtländer. Bidirectionalization for free! In Principles of Programming Languages, Proceedings, pages 165--176. ACM Press, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. D. Vytiniotis and S. Weirich. Type-safe cast does no harm: Syntactic parametricity for F-omega and beyond. Manuscript, 2009.Google ScholarGoogle Scholar
  28. P. Wadler. Theorems for free! In Functional Programming Languages and Computer Architecture, Proceedings, pages 347--359. ACM Press, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. P. Wadler. The essence of functional programming (Invited talk). In Principles of Programming Languages, Proceedings, pages 1--14. ACM Press, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Free theorems involving type constructor classes: functional pearl

        Recommendations

        Comments

        Login options

        Check if you have access through your login credentials or your institution to get full access on this article.

        Sign in

        Full Access

        • Published in

          cover image ACM SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 44, Issue 9
          ICFP '09
          September 2009
          343 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/1631687
          Issue’s Table of Contents
          • cover image ACM Conferences
            ICFP '09: Proceedings of the 14th ACM SIGPLAN international conference on Functional programming
            August 2009
            364 pages
            ISBN:9781605583327
            DOI:10.1145/1596550

          Copyright © 2009 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 31 August 2009

          Check for updates

          Qualifiers

          • research-article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!