skip to main content
research-article
Free Access

Witnessing side effects

Published:21 May 2008Publication History
Skip Abstract Section

Abstract

We present a new approach to the old problem of adding global mutable state to purely functional languages. Our idea is to extend the language with “witnesses,” which is based on an arguably more pragmatic motivation than past approaches. We give a semantic condition for correctness and prove it is sufficient. We also give a somewhat surprising static checking algorithm that makes use of a network flow property equivalent to the semantic condition via reduction to a satisfaction problem for a system of linear inequalities.

References

  1. Achten, P., van Groningen, J. H. G., and Plasmeijer, R. 1993. High level specification of I/O in functional languages. In Proceedings of the 1992 Glasgow Workshop on Functional Programming. Springer-Verlag, New York, 1--17. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Ariola, Z. M. and Felleisen, M. 1997. The call-by-need lambda calculus. J. Funct. Prog. 7, 3, 265--301. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Ariola, Z. M., Maraist, J., Odersky, M., Felleisen, M., and Wadler, P. 1995. A call-by-need lambda calculus. In Proceedings of the 22nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (San Francisco, CA). ACM, New York, 233--246. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Ariola, Z. M. and Sabry, A. 1998. Correctness of monadic state: an imperative call-by-need calculus. In Proceedings of the 25th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (San Diego, CA). 62--74. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Boyland, J. 2003. Checking interference with fractional permissions. In Static Analysis, Tenth International Symposium (San Diego, CA). 55--72. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Crary, K., Walker, D., and Morrisett, G. 1999. Typed memory management in a calculus of capabilities. In Proceedings of the 26th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (San Antonio, TX). 262--275. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Fähndrich, M., Foster, J. S., Su, Z., and Aiken, A. 1998. Partial online cycle elimination in inclusion constraint graphs. In Proceedings of the 1998 ACM SIGPLAN Conference on Programming Language Design and Implementation (Montreal, Ont., Canada). ACM, New York, 85--96. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Grossman, D., Morrisett, G., Jim, T., Hicks, M., Wang, Y., and Cheney, J. 2002. Region-based memory management in Cyclone. In Proceedings of the 2002 ACM SIGPLAN Conference on Programming Language Design and Implementation (Berlin, Germany). ACM, New York. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Guzman, J. C. and Hudak, P. 1990. Single-threaded polymorphic lambda calculus. In Proceedings of the 5th Annual IEEE Symposium on Logic in Computer Science (Philadelphia, PA). IEEE Computer Society Press, Los Alamitos, CA, 42--51.Google ScholarGoogle Scholar
  10. Launchbury, J. 1993. A natural semantics for lazy evaluation. In Proceedings of the 20th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Charleston, SC). ACM, New York, 144--154. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Launchbury, J. and Sabry, A. 1997. Monadic state: Axiomatization of type safety. In Proceedings of the 1997 ACM SIGPLAN International Conference on Functional Programming (Amsterdam, The Netherlands). ACM, New York, 227--238. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Matthews, J. and Findler, R. B. 2005. An operational semantics for r5rs scheme. In Proceedings of the 2005 Workshop on Scheme and Functional Programming.Google ScholarGoogle Scholar
  13. Moggi, E. 1991. Notions of computation and monads. Inf. Comput. 93, 1, 55--92. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Moggi, E. and Sabry, A. 2001. Monadic encapsulation of effects: a revised approach (extended version). J. Funct. Prog. 11, 6, 591--627. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Odersky, M., Rabin, D., and Hudak, P. 1993. Call by name, assignment, and the lambda calculus. In Proceedings of the 20th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Charleston, SC). ACM, New York, 43--56. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Peyton Jones, S. L. and Wadler, P. 1993. Imperative functional programming. In Proceedings of the 20th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Charleston, SC). ACM, New York, 71--84. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Plotkin, G. D. 1975. Call-by-name, call-by-value and the lambda-calculus. Theoret. Comput. Sci. 1, 125--159.Google ScholarGoogle ScholarCross RefCross Ref
  18. Sabry, A. 1998. What is a purely functional language? J. Funct. Prog. 8, 1, 1--22. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Semmelroth, M. and Sabry, A. 1999. Monadic encapsulation in ml. In Proceedings of the 4th ACM SIGPLAN International Conference on Functional Programming (Paris, France). ACM, New York, 8--17. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Sestoft, P. 1989. Replacing function parameters by global variables. In FPCA '89 Conference on Functional Programming Languages and Computer Architecture (London, United Kingdom). Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Terauchi, T. and Aiken, A. 2004. Memory management with use-counted regions. Tech. Rep. UCB//CSD-04-1314, University of California, Berkeley, CA. Mar.Google ScholarGoogle Scholar
  22. Terauchi, T. and Aiken, A. 2005. Witnessing side-effects. In Proceedings of the 8th ACM SIGPLAN International Conference on Functional Programming (Tallinn, Estonia). ACM, New York, 105--115. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Terauchi, T. and Aiken, A. 2006. A capability calculus for concurrency and determinism. In CONCUR 2006—Concurrency Theory, 17th International Conference (Bonn, Germany). 218--232. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Tofte, M. and Talpin, J.-P. 1994. Implementation of the typed call-by-value λ-calculus using a stack of regions. In Proceedings of the 21st Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Portland, OR). ACM, New York, 188--201. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Turner, D. N., Wadler, P., and Mossin, C. 1995. Once upon a type. In FPCA '95 Conference on Functional Programming Languages and Computer Architecture (La Jolla, CA), 1--11. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Wadler, P. 1990. Linear types can change the world! In IFIP TC 2, Proceedings of the Working Conference on Programming Concepts and Methods (Sea of Galilee, Israel), M. Broy and C. Jones, Eds. North Holland, Amsterdam, The Netherlands, 347--359.Google ScholarGoogle Scholar
  27. Wright, A. K. and Felleisen, M. 1994. A syntactic approach to type soundness. Inf. Comput. 115, 1, 38--94. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Witnessing side effects

          Recommendations

          Reviews

          Markus Wolf

          While functional programming languages have been an active research area due to their implicit parallelism and appeal for formal reasoning, there have been few industrial applications, mainly because of the lack of a natural concept of memory and side effects. Theoretical constructs proposed as a solution-the most well-known being monads-have difficult theoretical underpinnings and break the implicit parallelism. This paper proposes a novel way of dealing with state in functional programming languages. A new language construct, called a witness, is added to the functional core, allowing the expression of read/write dependencies without imposing a strict sequentiality. The paper consists of six sections and two appendices. The first section is an introduction motivating the work and listing the contribution of Terauchi and Aiken. This is followed by a section introducing an augmented λ-calculus containing syntax for creating storage locations, including reading from and writing to storage. Next, Terauchi and Aiken explain the reduction properties of the calculus, showing that the calculus in its simple form is nonconfluent-that is, two different terminating reductions of the same expression may yield different results. The following two sections are devoted to a special property of programs that recreate confluence, meaning that all programs exhibiting this property are confluent. Very simply put, the property states that, when reading from a memory location, there is a unique write to the location that is the same, independent from the reduction order. The core calculus is then slightly augmented and a type system guaranteeing confluence is presented. The last two sections discuss related work and summarize the major achievements of the paper. The appendices contain technical details and the complete proofs of the major theorems. The paper is very well written, making it easy to understand for anyone somewhat acquainted with λ-calculus and type systems. The results seem very interesting. Unfortunately, Terauchi and Aiken do not show what a real programming language example would look like, using their concept of witnesses. It is, of course, possible to reconstruct this from the calculus, but it would have been nice to include. Online Computing Reviews Service

          Access critical reviews of Computing literature here

          Become a reviewer for Computing Reviews.

          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 Transactions on Programming Languages and Systems
            ACM Transactions on Programming Languages and Systems  Volume 30, Issue 3
            May 2008
            245 pages
            ISSN:0164-0925
            EISSN:1558-4593
            DOI:10.1145/1353445
            Issue’s Table of Contents

            Copyright © 2008 ACM

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 21 May 2008
            • Accepted: 1 May 2007
            • Revised: 1 January 2007
            • Received: 1 April 2006
            Published in toplas Volume 30, Issue 3

            Permissions

            Request permissions about this article.

            Request Permissions

            Check for updates

            Qualifiers

            • research-article
            • Research
            • Refereed

          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!