A new approach to generic functional programming

Ralf Hinze
<span title="">2000</span> <i title="ACM Press"> <a target="_blank" rel="noopener" href="https://fatcat.wiki/container/2qaxtqe2rfgjnfefqcokcnzelq" style="color: black;">Proceedings of the 27th ACM SIGPLAN-SIGACT symposium on Principles of programming languages - POPL &#39;00</a> </i> &nbsp;
This paper describes a new approach to generic functional programming, which allows us to define functions generically for all datatypes expressible in Haskell. A generic function is one that is defined by induction on the structure of types. Typical examples include pretty printers, parsers, and comparison functions. The advanced type system of Haskell presents a real challenge: datatypes may be parameterized not only by types but also by type constructors, type definitions may involve mutual
more &raquo; ... ecursion, and recursive calls of type constructors can be arbitrarily nested. We show thatdespite this complexity-a generic function is uniquely defined by giving cases for primitive types and type constructors (such as disjoint unions and Cartesian products). Given this information a generic function can be specialized to arbitrary Haskell datatypes. The key idea of the approach is to model types by terms of the simply typed X-calculus augmented by a family of recursion operators. While conceptually simple, our approach places high demands on the type system: it requires polymorphic recursion, rank-n types, and a strong form of type constructor polymorphism. Finally, we point out connections to Haskell's class system and show that our approach generalizes type classes in some respects.
<span class="external-identifiers"> <a target="_blank" rel="external noopener noreferrer" href="https://doi.org/10.1145/325694.325709">doi:10.1145/325694.325709</a> <a target="_blank" rel="external noopener" href="https://dblp.org/rec/conf/popl/Hinze00.html">dblp:conf/popl/Hinze00</a> <a target="_blank" rel="external noopener" href="https://fatcat.wiki/release/3yvjrq7vt5hebozhcixu626qkm">fatcat:3yvjrq7vt5hebozhcixu626qkm</a> </span>
<a target="_blank" rel="noopener" href="https://web.archive.org/web/20190217103622/https://static.aminer.org/pdf/20170130/pdfs/popl/ns3tocjbc9podvvghfpilbxdf0twqn2z.pdf" title="fulltext PDF download" data-goatcounter-click="serp-fulltext" data-goatcounter-title="serp-fulltext"> <button class="ui simple right pointing dropdown compact black labeled icon button serp-button"> <i class="icon ia-icon"></i> Web Archive [PDF] <div class="menu fulltext-thumbnail"> <img src="https://blobs.fatcat.wiki/thumbnail/pdf/a3/1c/a31c6868cdd862cfdb822eab6c7898094e9e1f82.180px.jpg" alt="fulltext thumbnail" loading="lazy"> </div> </button> </a> <a target="_blank" rel="external noopener noreferrer" href="https://doi.org/10.1145/325694.325709"> <button class="ui left aligned compact blue labeled icon button serp-button"> <i class="external alternate icon"></i> acm.org </button> </a>