Denotational design with type class morphisms

Type classes provide a mechanism for varied implementations of standard interfaces. Many of these interfaces are founded in mathematical tradition and so have regularity not only of types but also of properties (laws) that must hold. Types and properties give strong guidance to the library implementor, while leaving freedom as well. Some of this remaining freedom is in how the implementation works, and some is in what it accomplishes. To give additional guidance to the what, without impinging on the how, this paper proposes a principle of type class morphisms (TCMs), which further refines the compositional style of denotational semantics. The TCM idea is simply that the instance’s meaning follows the meaning’s instance. This principle determines the meaning of each type class instance, and hence defines correctness of implementation. It also serves to transfer laws about a type’s semantic model, such as the class laws, to hold for the type itself. In some cases, it provides a systematic guide to implementation, and in some cases, valuable design feedback. The paper is illustrated with several examples of types, meanings, and morphisms.

[1]  Mark P. Jones A system of constructor classes: overloading and implicit higher-order polymorphism , 1993, FPCA '93.

[2]  Ralf Hinze,et al.  Generalizing generalized tries , 2000, Journal of Functional Programming.

[3]  Stephen Adams,et al.  Functional Pearls Efficient sets—a balancing act , 1993, Journal of Functional Programming.

[4]  Oege de Moor,et al.  Compiling embedded languages , 2003, J. Funct. Program..

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

[6]  Christopher Strachey,et al.  Toward a mathematical semantics for computer languages , 1971 .

[7]  Simon Peyton Jones,et al.  Playing by the rules: rewriting as a practical optimisation technique in GHC , 2001 .

[8]  Conal Elliott,et al.  Push-pull functional reactive programming , 2009, Haskell.

[9]  Ganesh Sittampalam,et al.  Paradise: a two-stage DSL embedded in Haskell , 2008, ICFP 2008.

[10]  Joseph E. Stoy,et al.  Denotational Semantics: The Scott-Strachey Approach to Programming Language Theory , 1981 .

[11]  Simon L. Peyton Jones,et al.  Associated types with class , 2005, POPL '05.

[12]  Paul Hudak,et al.  Functional reactive animation , 1997, ICFP '97.

[13]  Simon L. Peyton Jones,et al.  Simple unification-based type inference for GADTs , 2006, ICFP '06.

[14]  John Hughes,et al.  Generalising monads to arrows , 2000, Sci. Comput. Program..

[15]  Conal Elliott Denotational design with type class morphisms (extended version) DRAFT — comments please , 2009 .

[16]  John C. Reynolds,et al.  Using category theory to design implicit conversions and generic operators , 1980, Semantics-Directed Compiler Generation.

[17]  Conor McBride,et al.  Applicative programming with effects , 2008, J. Funct. Program..

[18]  Conal Elliott Beautiful differentiation , 2009, ICFP.