Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Compiling to categories

Published: 29 August 2017 Publication History

Abstract

It is well-known that the simply typed lambda-calculus is modeled by any cartesian closed category (CCC). This correspondence suggests giving typed functional programs a variety of interpretations, each corresponding to a different category. A convenient way to realize this idea is as a collection of meaning-preserving transformations added to an existing compiler, such as GHC for Haskell. This paper describes such an implementation and demonstrates its use for a variety of interpretations including hardware circuits, automatic differentiation, incremental computation, and interval analysis. Each such interpretation is a category easily defined in Haskell (outside of the compiler). The general technique appears to provide a compelling alternative to deeply embedded domain-specific languages.

References

[1]
Umut Acar. Self-adjusting computation . PhD thesis, School of Computer Science, Carnegie Mellon University, May 2005.
[2]
Umut A. Acar, Guy E. Blelloch, Matthias Blume, and Robert Harper. Self-adjusting programming . In ML Workshop, 2005.
[3]
Steve Awodey. Category theory, volume 49 of Oxford Logic Guides. Oxford University Press, 2006.
[4]
Christiaan Baaij and Jan Kuper. Using rewriting to synthesize functional languages to digital circuits . In Trends in Functional Programming, Lecture Notes in Computer Science, pages 17–33, 2014.
[5]
John Backus. Can programming be liberated from the von Neumann style? A functional style and its algebra of programs . Communications of the ACM, 21(8):613–641, August 1978.
[6]
Michael Barr. Fixed points in cartesian closed categories . Theoretical Computer Science, 70(1):65–72, 1990.
[7]
Per Bjesse, Koen Claessen, Mary Sheeran, and Satnam Singh. Lava: hardware design in Haskell . In ICFP, 1998.
[8]
Guy E. Blelloch. Prefix Sums and Their Applications . Technical Report CMU-CS-90-190, School of Computer Science, Carnegie Mellon University, November 1990.
[9]
Max Bolingbroke. Constraint kinds for GHC. http://blog.omega-prime.co.uk/?p=127, 2011.
[10]
Richard Boulton, Andrew Gordon, Mike Gordon, John Harrison, John Herbert, and John Van Tassel. Experience with embedding hardware description languages in HOL . In Proceedings of the IFIP TC10/WG 10.2 International Conference on Theorem Provers in Circuit Design: Theory, Practice and Experience, volume A-10, pages 129–156, 1993.
[11]
Yufei Cai, Paolo G. Giarrusso, Tillmann Rendel, and Klaus Ostermann. A theory of changes for higher-order languages: incrementalizing λ-calculi by static differentiation . In PLDI ’14, pages 145–155, 2014.
[12]
Magnus Carlsson. Monads for incremental computing . In ICFP, pages 26–35, 2002.
[13]
Manuel M. T. Chakravarty, Gabriele Keller, and Simon Peyton Jones. Associated type synonyms . In ICFP, 2005a.
[14]
Manuel M. T. Chakravarty, Gabriele Keller, Simon Peyton Jones, and Simon Marlow. Associated types with class . In Principles of Programming Languages, 2005b.
[15]
Mark Chu-Carroll. Interpreting lambda calculus using closed cartesian categories. http://goodmath.scientopia.org/2012/03/ 11/interpreting-lambda-calculus-using-closed-cartesian-categories/, March 2012.
[16]
Koen Claessen and David Sands. In Asian Computing Science Conference, 1999.
[17]
Guy Cousineau, Pierre-Louis Curien, and Michel Mauny. The categorical abstract machine . Science of Computer Programming, 8, 1987.
[18]
Pierre-Louis Curien. Categorical combinators. Information and Control, 69(1-3):188–254, 1986.
[19]
Leonardo De Moura and Nikolaj Bjørner. Z3: An efficient SMT solver . In Theory and Practice of Software, International Conference on Tools and Algorithms for the Construction and Analysis of Systems, pages 337–340, 2008.
[20]
Conal Elliott. Programming graphics processors functionally . In Haskell Workshop, 2004.
[21]
Conal Elliott. Beautiful differentiation . In International Conference on Functional Programming, 2009.
[22]
Conal Elliott. Generic functional parallel algorithms: Scan and FFT . Proc. ACM Program. Lang., 1(ICFP), September 2017.
[23]
Conal Elliott, Sigbjørn Finne, and Oege de Moor. Compiling embedded languages . Journal of Functional Prog., 13(2), 2003.
[24]
Andrew Farmer, Andy Gill, Ed Komp, and Neil Sculthorpe. The HERMIT in the machine: A plugin for the interactive transformation of GHC core language programs . Haskell Symposium, pages 1–12, 2012.
[25]
GHC Team. The Glorious Glasgow Haskell compilation system user’s guide, version 8.0.1. https://downloads.haskell.org/ ~ghc/latest/docs/html/users_guide, 2016.
[26]
Jeremy Gibbons. Calculating functional programs . In Algebraic and Coalgebraic Methods in the Mathematics of Program Construction, volume 2297 of Lecture Notes in Computer Science. Springer-Verlag, 2002.
[27]
Jeremy Gibbons and Nicolas Wu. Folding domain-specific languages: Deep and shallow embeddings . In ICFP, 2014.
[28]
Andy Gill. Type-safe observable sharing in Haskell . In Haskell Symposium, pages 117–128, September 2009.
[29]
Andy Gill. Domain-specific languages and code synthesis using Haskell . ACM Queue, 12(4), April 2014.
[30]
Andy Gill and Graham Hutton. The worker/wrapper transformation . Journal of Functional Prog., pages 227–251, 2009.
[31]
Ralf Hinze. Memo functions, polytypically! In Workshop on Generic Programming, pages 17–32, 2000.
[32]
Ralf Hinze. Fun with phantom types . In The fun of programming. Palgrave, 2003.
[33]
Ralf Hinze. Polytypic values possess polykinded types . In Science of Computer Programming, pages 2–27, June 2004.
[34]
John Hughes. The design of a pretty-printing library . In Advanced Functional Programming, pages 53–96, 1995.
[35]
John Hughes. Generalising monads to arrows . Science of Computer Programming, 37:67–111, 1998.
[36]
John Hughes and Simon Peyton Jones. The pretty package. https://hackage.haskell.org/package/pretty, November 2007. Haskell library.
[37]
Geraint Jones and Mary Sheeran. Circuit design in Ruby . Formal methods for VLSI design, 1, 1990.
[38]
Mark P. Jones. Dictionary-free overloading by partial evaluation . In In ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation, pages 107–117, 1994.
[39]
Jerzy Karczmarczuk. Functional differentiation of computer programs . In ICFP, pages 195–203, 1998.
[40]
Edward Kmett. What constraints entail: Part 1. http://comonad.com/reader/2011/what-constraints-entail-part-1/, 2011.
[41]
Joachim Lambek. From λ-calculus to cartesian closed categories. In J.P. Seldin and J.R. Hindley, editors, To H.B. Curry: Essays on Combinatory Logic, Lambda Calculus, and Formalism . Academic Press, 1980.
[42]
Joachim Lambek. Cartesian closed categories and typed lambda-calculi. In Thirteenth Spring School of the LITP on Combinators and Functional Programming Languages, pages 136–175, 1986.
[43]
F. William Lawvere and Stephen H. Schanuel. Conceptual Mathematics: A First Introduction to Categories. Cambridge University Press, 2nd edition, 2009.
[44]
Daan Leijen and Erik Meijer. Domain specific embedded compilers . In Conference on Domain-Specific Languages, pages 109–122, 1999.
[45]
José Pedro Magalhães, Atze Dijkstra, Johan Jeuring, and Andres Löh. A generic deriving mechanism for Haskell . In Haskell Symposium, pages 37–48, 2010.
[46]
José Pedro Magalhães et al. GHC.Generics, 2011. URL https://wiki.haskell.org/GHC.Generics . Haskell wiki page.
[47]
M. Douglas McIlroy. Power series, power serious . Journal of Functional Programming, 9(3):325–337, 1999.
[48]
R.E. Moore. Interval analysis. Series in automatic computation. Prentice-Hall, 1966.
[49]
Philip S. Mulry. Categorical fixed point semantics . Theoretical Computer Science, 70(1):85–97, January 1990.
[50]
Simon Peyton Jones and John Launchbury. Unboxed values as first class citizens in a non-strict functional language . In Functional programming languages and computer architecture, pages 636–666, 1991.
[51]
Simon Peyton Jones and Simon Marlow. Secrets of the Glasgow Haskell compiler inliner . Journal of Functional Programming, 12(5), July 2002.
[52]
Simon Peyton Jones, Andrew Tolmach, and Tony Hoare. Playing by the rules: Rewriting as a practical optimisation technique in GHC . In Haskell Workshop, pages 203–233, 2001.
[53]
Simon L. Peyton Jones. Compiling Haskell by program transformation: A report from the trenches . In European Symposium on Programming, pages 18–44, 1996.
[54]
Neil Sculthorpe, Jan Bracker, George Giorgidze, and Andy Gill. The constrained-monad problem . In International Conference on Functional Programming, pages 287–298, 2013a.
[55]
Neil Sculthorpe, Andrew Farmer, and Andy Gill. The HERMIT in the tree: Mechanizing program transformations in the GHC core language . In Symposium on Implementation and Application of Functional Languages, pages 86–103, 2013b.
[56]
Mary Sheeran. muFP, a language for VLSI design . In Symposium on LISP and Functional Programming, pages 104–112, 1984.
[57]
Alex Simpson and Gordon Plotkin. Complete axioms for categorical fixed-point operators . In Logic in Computer Science, pages 30–41, 2000.
[58]
Jeffrey Mark Siskind and Barak A. Pearlmutter. Perturbation confusion and referential transparency: Correct functional implementation of forward-mode AD . In Implementation and Application of Functional Languages, pages 1–9, 2005.
[59]
Jeffrey Mark Siskind and Barak A. Pearlmutter. Nesting forward-mode AD in a functional framework . Higher Order Symbolic Computation, 21(4):361–376, 2008.
[60]
Michael Spivak. Calculus on Manifolds: A Modern Approach to Classical Theorems of Advanced Calculus. HarperCollins Publishers, 1971.
[61]
Martin Sulzmann, Manuel M. T. Chakravarty, Simon L. Peyton Jones, and Kevin Donnelly. System F with type equality coercions . In Types In Languages Design And Implementation, pages 53–66, 2007.
[62]
Pierre Weis et al. A history of Caml, 2005. URL https://caml.inria.fr/about/history.en.html . Last updated 2005-01-28.
[63]
R. E. Wengert. A simple automatic derivative evaluation program. Communications of the ACM, 7(8):463–464, 1964.
[64]
Brent A. Yorgey, Stephanie Weirich, Julien Cretin, Simon L. Peyton Jones, Dimitrios Vytiniotis, and José Pedro Magalhães. Giving Haskell a promotion . In Types In Languages Design And Implementation, pages 53–66. ACM, 2012.

Cited By

View all
  • (2024)Calculating Compilers Effectively (Functional Pearl)Proceedings of the 17th ACM SIGPLAN International Haskell Symposium10.1145/3677999.3678283(109-119)Online publication date: 29-Aug-2024
  • (2024)Decapodes: A diagrammatic tool for representing, composing, and computing spatialized partial differential equationsJournal of Computational Science10.1016/j.jocs.2024.10234581(102345)Online publication date: Sep-2024
  • (2024)Algebraic Dynamical Systems in Machine LearningApplied Categorical Structures10.1007/s10485-023-09762-932:1Online publication date: 18-Jan-2024
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 1, Issue ICFP
September 2017
1173 pages
EISSN:2475-1421
DOI:10.1145/3136534
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike International 4.0 License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 29 August 2017
Published in PACMPL Volume 1, Issue ICFP

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. category theory
  2. compile-time optimization
  3. domain-specific languages

Qualifiers

  • Research-article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)205
  • Downloads (Last 6 weeks)27
Reflects downloads up to 25 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Calculating Compilers Effectively (Functional Pearl)Proceedings of the 17th ACM SIGPLAN International Haskell Symposium10.1145/3677999.3678283(109-119)Online publication date: 29-Aug-2024
  • (2024)Decapodes: A diagrammatic tool for representing, composing, and computing spatialized partial differential equationsJournal of Computational Science10.1016/j.jocs.2024.10234581(102345)Online publication date: Sep-2024
  • (2024)Algebraic Dynamical Systems in Machine LearningApplied Categorical Structures10.1007/s10485-023-09762-932:1Online publication date: 18-Jan-2024
  • (2024)Asynchronous Reactive Programming with Modal Types in HaskellPractical Aspects of Declarative Languages10.1007/978-3-031-52038-9_2(18-36)Online publication date: 15-Jan-2024
  • (2023)Crafting Extensible Forward Incremental Parallel Embedded Build SystemsProceedings of the 35th Symposium on Implementation and Application of Functional Languages10.1145/3652561.3652568(1-11)Online publication date: 29-Aug-2023
  • (2023)The Essence of ReactivityProceedings of the 16th ACM SIGPLAN International Haskell Symposium10.1145/3609026.3609727(18-31)Online publication date: 30-Aug-2023
  • (2023)Embedding by UnembeddingProceedings of the ACM on Programming Languages10.1145/36078307:ICFP(1-47)Online publication date: 31-Aug-2023
  • (2023)Grisette: Symbolic Compilation as a Functional Programming LibraryProceedings of the ACM on Programming Languages10.1145/35712097:POPL(455-487)Online publication date: 11-Jan-2023
  • (2023)Embedding Functional Logic Programming in Haskell via a Compiler PluginPractical Aspects of Declarative Languages10.1007/978-3-031-24841-2_3(37-55)Online publication date: 8-Jan-2023
  • (2022)Structured Combinators for Efficient Graph ReductionIEEE Computer Architecture Letters10.1109/LCA.2022.319884421:2(73-76)Online publication date: 1-Jul-2022
  • Show More Cited By

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media