Free Theorems Involving Type Constructor Classes

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

[1]  John C. Reynolds,et al.  Types, Abstraction and Parametric Polymorphism , 1983, IFIP Congress.

[2]  John C. Mitchell,et al.  Second-Order Logical Relations (Extended Abstract) , 1985, Logic of Programs.

[3]  John Hughes,et al.  A Novel Representation of Lists and its Application to the Function "reverse" , 1986, Inf. Process. Lett..

[4]  Philip Wadler,et al.  Theorems for free! , 1989, FPCA.

[5]  Philip Wadler,et al.  How to make ad-hoc polymorphism less ad hoc , 1989, POPL '89.

[6]  Eugenio Moggi,et al.  Notions of Computation and Monads , 1991, Inf. Comput..

[7]  Simon L. Peyton Jones,et al.  A short cut to deforestation , 1993, FPCA '93.

[8]  Simon L. Peyton Jones,et al.  Imperative functional programming , 1993, POPL '93.

[9]  Paul Hudak,et al.  Monad transformers and modular interpreters , 1995, POPL '95.

[10]  Simon L. Peyton Jones,et al.  State in Haskell , 1995, LISP Symb. Comput..

[11]  Tim Sheard,et al.  Revisiting catamorphisms over datatypes with embedded functions (or, programs from outer space) , 1996, POPL '96.

[12]  J. Kucan Metatheorems about convertibility in typed lambda calculi : applications to CPS transform and "free theorems" , 1997 .

[13]  Philip Wadler,et al.  The essence of functional programming (Invited talk) , 1997 .

[14]  Janis Voigtländer,et al.  Concatenate, reverse and map vanish for free , 2002, ICFP '02.

[15]  Patricia Johann,et al.  Free theorems in the presence of seq , 2004, POPL.

[16]  Nils Anders Danielsson,et al.  Fast and loose reasoning is morally correct , 2006, POPL '06.

[17]  Wouter Swierstra,et al.  Beauty in the Beast A Functional Semantics for the Awkward Squad , 2007 .

[18]  Andrzej Filinski On the relations between monadic semantics , 2007, Theor. Comput. Sci..

[19]  Andrzej Filinski,et al.  Inductive reasoning about effectful data types , 2007, ICFP '07.

[20]  Stephanie Weirich,et al.  Type-safe cast does no harm , 2007 .

[21]  Lars Birkedal,et al.  Ynot: dependent types for imperative programs , 2008, ICFP 2008.

[22]  Janis Voigtländer,et al.  Asymptotic Improvement of Computations over Free Monads , 2008, MPC.

[23]  Wouter Swierstra,et al.  Data types à la carte , 2008, Journal of Functional Programming.

[24]  Janis Voigtländer,et al.  Parametricity for Haskell with Imprecise Error Semantics , 2009, TLCA.