skip to main content
10.1145/2804302.2804310acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Functional pearl: getting a quick fix on comonads

Published:30 August 2015Publication History

ABSTRACT

A piece of functional programming folklore due to Piponi provides Löb's theorem from modal provability logic with a computational interpretation as an unusual fixed point. Interpreting modal necessity as an arbitrary Functor in Haskell, the "type" of Löb's theorem is inhabited by a fixed point function allowing each part of a structure to refer to the whole. However, Functor's logical interpretation may be used to prove Löb's theorem only by relying on its implicit functorial strength, an axiom not available in the provability modality. As a result, the well known loeb fixed point "cheats" by using functorial strength to implement its recursion. Rather than Functor, a closer Curry analogue to modal logic's Howard inspiration is a closed (semi-)comonad, of which Haskell's ComonadApply typeclass provides analogous structure. Its computational interpretation permits the definition of a novel fixed point function allowing each part of a structure to refer to its own context within the whole. This construction further guarantees maximal sharing and asymptotic efficiency superior to loeb for locally contextual computations upon a large class of structures. With the addition of a distributive law, closed comonads may be composed into spaces of arbitrary dimensionality while preserving the performance guarantees of this new fixed point. From these elements, we construct a small embedded domain-specific language to elegantly express and evaluate multidimensional "spreadsheet-like" recurrences for a variety of cellular automata.

References

  1. D. Ahmen, J. Chapman, and T. Uustalu. When is a Container a Comonad? Logical Methods in Computer Science, 10(3), 2014.Google ScholarGoogle Scholar
  2. N. Alechina, M. Mendler, V. D. Paiva, and E. Ritter. Categorical and Kripke Semantics for Constructive S4 Modal Logic. Computer Science Logic, pages 292–307, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. G. M. Beirman and V. C. V. D. Paiva. Intuitionistic Necessity Revisited. Technical report, University of Birmingham, School of Computer Science, 1996.Google ScholarGoogle Scholar
  4. S. Capobianco and T. Uustalu. A Categorical Outlook on Cellular Automata. arXiv preprint arXiv:1012.1220, 2010.Google ScholarGoogle Scholar
  5. C. Done. Twitter Waterflow Problem and Loeb, 2014. URL chrisdone.com/posts/twitter-problem-loeb.Google ScholarGoogle Scholar
  6. J. Epstein, A. Black, and S. Peyton-Jones. Towards Haskell in the Cloud. In ACM SIGPLAN Notices, volume 46, pages 118–129. ACM, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. M. Gardner. The Fantastic Combinations of John Conway’s New Solitaire Game “Life”. Scientific American, 223(4): 120–123, October 1970.Google ScholarGoogle ScholarCross RefCross Ref
  8. J. Garson. Modal Logic. Stanford Encyclopedia of Philosophy, 2014. URL plato.stanford.edu/entries/logic-modal.Google ScholarGoogle Scholar
  9. G. Huet. Functional Pearl: The Zipper. Journal of Functional Programming, 7(5):549–554, September 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. E. Kmett. The Comonad Package, July 2014. URL hackage.haskell.org/package/comonad.Google ScholarGoogle Scholar
  11. E. Kmett. The Distributive Package, May 2014. URL hackage.haskell.org/package/distributive.Google ScholarGoogle Scholar
  12. A. Kock. Strong Functors and Monoidal Monads. Archiv der Mathematik, 23(1):113–120, 1972.Google ScholarGoogle ScholarCross RefCross Ref
  13. S. Lindley and C. McBride. Hasochism: the Pleasure and Pain of Dependently Typed Haskell Programming. In Proceedings of the 2013 ACM SIGPLAN Symposium on Haskell, pages 81–92, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. P. Lindstrom. Notes on Some Fixed Point Constructions in Provability Logic. Journal of Philosophical Logic, 35(3): 225–230, 2006.Google ScholarGoogle ScholarCross RefCross Ref
  15. E. Mendelson. Introduction to Mathematical Logic. CRC Press, 4 edition, 1997.Google ScholarGoogle Scholar
  16. D. Menendez. Paper: The Essence of Dataflow Programming. Haskell mailing list archive. URL mail.haskell.org/ pipermail/haskell/2005-September/016502.html.Google ScholarGoogle Scholar
  17. D. Orchard. Programming Contextual Computations. Technical Report UCAM-CL-TR-854, University of Cambridge, Computer Laboratory, May 2014.Google ScholarGoogle Scholar
  18. D. Piponi. From Löb’s Theorem to Spreadsheet Evaluation, November 2006. URL blog.sigfpe.com/2006/11/ from-l-theorem-to-spreadsheet.html.Google ScholarGoogle Scholar
  19. T. Uustalu and V. Vene. Comonadic Notions of Computation. Electronic Notes in Theoretical Computer Science, 203(5): 263–284, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. T. Uustalu and V. Vene. The Essence of Dataflow Programming. Lecture Notes in Computer Science, 4164: 135–167, November 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. N. Vazou, E. L. Seidel, R. Jhala, D. Vytiniotis, and S. Peyton-Jones. Refinement Types for Haskell. Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming, pages 269–282, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Functional pearl: getting a quick fix on comonads

            Recommendations

            Comments

            Login options

            Check if you have access through your login credentials or your institution to get full access on this article.

            Sign in
            • Published in

              cover image ACM Conferences
              Haskell '15: Proceedings of the 2015 ACM SIGPLAN Symposium on Haskell
              August 2015
              212 pages
              ISBN:9781450338080
              DOI:10.1145/2804302
              • cover image ACM SIGPLAN Notices
                ACM SIGPLAN Notices  Volume 50, Issue 12
                Haskell '15
                December 2015
                212 pages
                ISSN:0362-1340
                EISSN:1558-1160
                DOI:10.1145/2887747
                Issue’s Table of Contents

              Copyright © 2015 ACM

              Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

              Publisher

              Association for Computing Machinery

              New York, NY, United States

              Publication History

              • Published: 30 August 2015

              Permissions

              Request permissions about this article.

              Request Permissions

              Check for updates

              Qualifiers

              • research-article

              Acceptance Rates

              Overall Acceptance Rate57of143submissions,40%

              Upcoming Conference

              ICFP '24
            • Article Metrics

              • Downloads (Last 12 months)17
              • Downloads (Last 6 weeks)0

              Other Metrics

            PDF Format

            View or Download as a PDF file.

            PDF

            eReader

            View online with eReader.

            eReader