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.
- D. Ahmen, J. Chapman, and T. Uustalu. When is a Container a Comonad? Logical Methods in Computer Science, 10(3), 2014.Google Scholar
- 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 Scholar
Digital Library
- G. M. Beirman and V. C. V. D. Paiva. Intuitionistic Necessity Revisited. Technical report, University of Birmingham, School of Computer Science, 1996.Google Scholar
- S. Capobianco and T. Uustalu. A Categorical Outlook on Cellular Automata. arXiv preprint arXiv:1012.1220, 2010.Google Scholar
- C. Done. Twitter Waterflow Problem and Loeb, 2014. URL chrisdone.com/posts/twitter-problem-loeb.Google Scholar
- 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 Scholar
Digital Library
- M. Gardner. The Fantastic Combinations of John Conway’s New Solitaire Game “Life”. Scientific American, 223(4): 120–123, October 1970.Google Scholar
Cross Ref
- J. Garson. Modal Logic. Stanford Encyclopedia of Philosophy, 2014. URL plato.stanford.edu/entries/logic-modal.Google Scholar
- G. Huet. Functional Pearl: The Zipper. Journal of Functional Programming, 7(5):549–554, September 1997. Google Scholar
Digital Library
- E. Kmett. The Comonad Package, July 2014. URL hackage.haskell.org/package/comonad.Google Scholar
- E. Kmett. The Distributive Package, May 2014. URL hackage.haskell.org/package/distributive.Google Scholar
- A. Kock. Strong Functors and Monoidal Monads. Archiv der Mathematik, 23(1):113–120, 1972.Google Scholar
Cross Ref
- 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 Scholar
Digital Library
- P. Lindstrom. Notes on Some Fixed Point Constructions in Provability Logic. Journal of Philosophical Logic, 35(3): 225–230, 2006.Google Scholar
Cross Ref
- E. Mendelson. Introduction to Mathematical Logic. CRC Press, 4 edition, 1997.Google Scholar
- D. Menendez. Paper: The Essence of Dataflow Programming. Haskell mailing list archive. URL mail.haskell.org/ pipermail/haskell/2005-September/016502.html.Google Scholar
- D. Orchard. Programming Contextual Computations. Technical Report UCAM-CL-TR-854, University of Cambridge, Computer Laboratory, May 2014.Google Scholar
- 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 Scholar
- T. Uustalu and V. Vene. Comonadic Notions of Computation. Electronic Notes in Theoretical Computer Science, 203(5): 263–284, 2008. Google Scholar
Digital Library
- T. Uustalu and V. Vene. The Essence of Dataflow Programming. Lecture Notes in Computer Science, 4164: 135–167, November 2006. Google Scholar
Digital Library
- 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 Scholar
Digital Library
Index Terms
Functional pearl: getting a quick fix on comonads
Recommendations
Functional pearl: getting a quick fix on comonads
Haskell '15: Proceedings of the 2015 ACM SIGPLAN Symposium on HaskellA 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 ...
Coherence for monoidal monads and comonads†
The goal of this paper is to prove coherence results with respect to relational graphs for monoidal monads and comonads, that is, monads and comonads in a monoidal category such that the endofunctor of the monad or comonad is a monoidal functor (this ...
Theorem proving for all: equational reasoning in liquid Haskell (functional pearl)
Haskell '18Equational reasoning is one of the key features of pure functional languages such as Haskell. To date, however, such reasoning always took place externally to Haskell, either manually on paper, or mechanised in a theorem prover. This article shows how ...






Comments