skip to main content
research-article

Productive coprogramming with guarded recursion

Published:25 September 2013Publication History
Skip Abstract Section

Abstract

Total functional programming offers the beguiling vision that, just by virtue of the compiler accepting a program, we are guaranteed that it will always terminate. In the case of programs that are not intended to terminate, e.g., servers, we are guaranteed that programs will always be productive. Productivity means that, even if a program generates an infinite amount of data, each piece will be generated in finite time. The theoretical underpinning for productive programming with infinite output is provided by the category theoretic notion of final coalgebras. Hence, we speak of coprogramming with non-well-founded codata, as a dual to programming with well-founded data like finite lists and trees.

Systems that offer facilities for productive coprogramming, such as the proof assistants Coq and Agda, currently do so through syntactic guardedness checkers. Syntactic guardedness checkers ensure that all self-recursive calls are guarded by a use of a constructor. Such a check ensures productivity. Unfortunately, these syntactic checks are not compositional, and severely complicate coprogramming.

Guarded recursion, originally due to Nakano, is tantalising as a basis for a flexible and compositional type-based approach to coprogramming. However, as we show, by itself, guarded recursion is not suitable for coprogramming due to the fact that there is no way to make finite observations on pieces of infinite data. In this paper, we introduce the concept of clock variables that index Nakano's guarded recursion. Clock variables allow us to "close over" the generation of infinite data, and to make finite observations, something that is not possible with guarded recursion alone.

References

  1. A. Abel. Termination checking with types. ITA, 38 (4): 277--319, 2004.Google ScholarGoogle Scholar
  2. A. W. Appel and D. A. McAllester. An indexed model of recursive types for foundational proof-carrying code. ACM Trans. Program. Lang. Syst., 23 (5): 657--683, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. R. S. Bird. Using Circular Programs to Eliminate Multiple Traversals of Data. Acta Informatica, 21: 239--250, 1984.Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. L. Birkedal and R. E. Møgelberg. Intensional type theory with guarded recursive types qua fixed points on universes. In ACM/IEEE Symposium on Logic in Computer Science (LICS 2013), 2013.Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. L. Birkedal, J. Schwinghammer, and K. Støvring. A metric model of guarded recursion. In Presented at FICS 2010, 2010.Google ScholarGoogle Scholar
  6. L. Birkedal, R. E. Møgelberg, J. Schwinghammer, and K. Støvring. First steps in synthetic guarded domain theory: step-indexing in the topos of trees. Log. Meth. in Computer Science, 8 (4), 2012.Google ScholarGoogle ScholarCross RefCross Ref
  7. V. Capretta. General recursion via coinductive types. Log. Meth. in Computer Science, 1 (2), 2005.Google ScholarGoogle Scholar
  8. N. A. Danielsson. Beating the productivity checker using embedded languages. In Workshop on Partiality and Recursion in Interactive Theorem Provers (PAR 2010), volume 43 of EPTCS, pages 29--48, 2010.Google ScholarGoogle ScholarCross RefCross Ref
  9. N. A. Danielsson and T. Altenkirch. Mixing induction and coinduction. Draft, 2009.Google ScholarGoogle Scholar
  10. D. Dreyer, A. Ahmed, and L. Birkedal. Logical step-indexed logical relations. Log. Meth. in Computer Science, 7 (2), 2011.Google ScholarGoogle Scholar
  11. N. Ghani, P. Hancock, and D. Pattinson. Representations of stream processors using nested fixed points. Log. Meth. in Computer Science, 5 (3), 2009.Google ScholarGoogle Scholar
  12. E. Giménez. Codifying guarded definitions with recursive schemes. In Types for Proofs and Programs, International Workshop TYPES'94, volume 996 of Lecture Notes in Computer Science, pages 39--59, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. G. Hutton and M. Jaskelioff. Representing contractive functions on streams. Submitted, 2011.Google ScholarGoogle Scholar
  14. N. R. Krishnaswami and N. Benton. A semantic model for graphical user interfaces. In ACM SIGPLAN international conference on Functional Programming, ICFP 2011, pages 45--57, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. N. R. Krishnaswami and N. Benton. Ultrametric semantics of reactive programs. In IEEE Symposium on Logic in Computer Science, LICS 2011, pages 257--266, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. J. Launchbury and S. L. Peyton Jones. Lazy functional state threads. In Proceedings of the ACM SIGPLAN'94 Conference on Programming Language Design and Implementation (PLDI), pages 24--35, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. R. Loader. Equational Theories for Inductive Types. Annals of Pure and Applied Logic, 84 (2): 175--217, 1997.Google ScholarGoogle ScholarCross RefCross Ref
  18. C. McBride and R. Paterson. Applicative programming with effects. J. Funct. Prog., 18 (1): 1--13, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. E. Moggi and A. Sabry. Monadic encapsulation of effects: a revised approach (extended version). J. Funct. Prog., 11 (6): 591--627, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. H. Nakano. A modality for recursion. In IEEE Symposium on Logic in Computer Science (LICS 2000), pages 255--266, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. A. M. Pitts. Computational adequacy via 'mixed' inductive definitions. In Mathematical Foundations of Programming Semantics, Proc. 9th Int. Conf., volume 802 of Lecture Notes in Computer Science, pages 72--82. Springer-Verlag, Berlin, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. P. Severi and F.-J. de Vries. Pure type systems with corecursion on streams: from finite to infinitary normalisation. In ACM SIGPLAN International Conference on Functional Programming, ICFP'12, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. M. B. Smyth and G. D. Plotkin. The category-theoretic solution of recursive domain equations. SIAM J. Comput., 11 (4): 761--783, 1982.Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. A. Tarski. A lattice-theoretical fixpoint theorem and its applications. Pacific Journal of Mathematics, 5 (2): 285--309, 1955.Google ScholarGoogle ScholarCross RefCross Ref

Index Terms

  1. Productive coprogramming with guarded recursion

                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

                Full Access

                • Published in

                  cover image ACM SIGPLAN Notices
                  ACM SIGPLAN Notices  Volume 48, Issue 9
                  ICFP '13
                  September 2013
                  457 pages
                  ISSN:0362-1340
                  EISSN:1558-1160
                  DOI:10.1145/2544174
                  Issue’s Table of Contents
                  • cover image ACM Conferences
                    ICFP '13: Proceedings of the 18th ACM SIGPLAN international conference on Functional programming
                    September 2013
                    484 pages
                    ISBN:9781450323260
                    DOI:10.1145/2500365

                  Copyright © 2013 ACM

                  Publisher

                  Association for Computing Machinery

                  New York, NY, United States

                  Publication History

                  • Published: 25 September 2013

                  Check for updates

                  Qualifiers

                  • research-article

                PDF Format

                View or Download as a PDF file.

                PDF

                eReader

                View online with eReader.

                eReader
                About Cookies On This Site

                We use cookies to ensure that we give you the best experience on our website.

                Learn more

                Got it!