Functional pearl: getting a quick fix on comonads

Kenneth Foner
2015 SIGPLAN notices  
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
more » ... m 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 more faithful Curry to modal logic's Howard is a closed 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. By adding a distributive law, closed comonads may be composed into spaces of arbitrary dimensionality which preserve the performance guarantees of this new fixed point. Applications of this technique include calculation of multidimensional "spreadsheet-like
doi:10.1145/2887747.2804310 fatcat:iuxkqhvxnvdgnp4q4j5dmeznd4