A pattern for almost homomorphic functions

Modern type systems present the programmer with a trade-off between correctness and code complexity--more precise, or exact, types that allow only legal values prevent runtime errors while less precise types enable more reuse. Unfortunately, the software engineering benefits of reuse and avoiding duplicate code currently outweigh assurance gains of exact types. We factor out a pattern common in conversions that result from using exact types as a reusable function, extending existing generic programming techniques to avoid code duplication and enable reuse.

[1]  Nathan Mishra-Linger,et al.  Programming in Omega , 2008, CEFP.

[2]  Richard S. Bird,et al.  Nested Datatypes , 1998, MPC.

[3]  Johan Jeuring,et al.  A generic deriving mechanism for Haskell , 2010, Haskell '10.

[4]  Manuel M. T. Chakravarty,et al.  Instant Generics: Fast and Easy , 2009 .

[5]  D. Turner Total Functional Programming , 2004, J. Univers. Comput. Sci..

[6]  José Pedro Magalhães The right kind of generic programming , 2012, WGP '12.

[7]  Peter D. Mosses,et al.  CASL: the Common Algebraic Specification Language , 2002, Theor. Comput. Sci..

[8]  Simon L. Peyton Jones,et al.  OutsideIn(X) Modular type inference with local assumptions , 2011, J. Funct. Program..

[9]  Simon L. Peyton Jones,et al.  Scrap your boilerplate: a practical design pattern for generic programming , 2003, TLDI '03.

[10]  Furio Honsell,et al.  A framework for defining logics , 1993, JACM.

[11]  Jacques Garrigue,et al.  Programming with Polymorphic Variants , 2010 .

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

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

[14]  Simon L. Peyton Jones,et al.  Giving Haskell a promotion , 2012, TLDI '12.

[15]  Aarne Ranta,et al.  A pattern for almost compositional functions , 2008, J. Funct. Program..

[16]  R. Kent Dybvig,et al.  A nanopass infrastructure for compiler education , 2004, ICFP '04.

[17]  Andres Löh,et al.  A Formal Comparison of Approaches to Datatype-Generic Programming , 2012, MSFP.

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

[19]  Johan Jeuring,et al.  Optimizing generics is easy! , 2010, PEPM '10.

[20]  Johan Jeuring,et al.  Generic programming with fixed points for mutually recursive datatypes , 2009, ICFP.

[21]  Ralf Lämmel,et al.  Strongly typed heterogeneous collections , 2004, Haskell '04.

[22]  Philip Wadler,et al.  The essence of functional programming , 1992, POPL '92.

[23]  Simon L. Peyton Jones,et al.  Type checking with open type functions , 2008, ICFP.

[24]  Johan Jeuring,et al.  Generic programming for indexed datatypes , 2011, WGP@ICFP.