skip to main content
research-article

Wormholes: introducing effects to FRP

Published:13 September 2012Publication History
Skip Abstract Section

Abstract

Functional reactive programming (FRP) is a useful model for programming real-time and reactive systems in which one defines a signal function to process a stream of input values into a stream of output values. However, performing side effects (e.g. memory mutation or input/output) in this model is tricky and typically unsafe. In previous work, Winograd-Cort et al. [2012] introduced resource types and wormholes to address this problem.

This paper better motivates, expands upon, and formalizes the notion of a wormhole to fully unlock its potential. We show, for example, that wormholes can be used to define the concept of causality. This in turn allows us to provide behaviors such as looping, a core component of most languages, without building it directly into the language. We also improve upon our previous design by making wormholes less verbose and easier to use.

To formalize the notion of a wormhole, we define an extension to the simply typed lambda calculus, complete with typing rules and operational semantics. In addition, we present a new form of semantic transition that we call a temporal transition to specify how an FRP program behaves over time and to allow us to better reason about causality. As our model is designed for a Haskell implementation, the semantics are lazy. Finally, with the language defined, we prove that our wormholes indeed allow side effects to be performed safely in an FRP framework.

References

  1. G. Berry and L. Cosserat. The Esterel synchronous programming language and its mathematical semantics. In Seminar on Concurrency, volume 197 of Lecture Notes in Computer Science, pages 389--448. Springer-Verlag, July 1984. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. T. Brus, M. van Eekelen, M. van Leer, M. Plasmeijer, and H. Barendregt. CLEAN - A language for functional graph rewriting. In Functional Programming Languages and Computer Architecture, volume 274 of Lecture Notes in Computer Science, pages 364--384. Springer-Verlag, September 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. P. Caspi, D. Pilaud, N. Halbwachs, and J. A. Plaice. Lustre: A declarative language for programming synchronous systems. In 14th Symposium on Principles of Programming Languages, pages 178--188. ACM, January 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. G. H. Cooper. Integrating dataflow evaluation into a practical higher-order call-by-value language. PhD thesis, Brown University, Providence, RI, USA, May 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. G. H. Cooper and S. Krishnamurthi. Embedding dynamic dataflow in a call-by-value language. In Programming Languages and Systems, volume 3924 of Lecture Notes in Computer Science, pages 294--308. Springer-Verlag, March 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. A. Courtney, H. Nilsson, and J. Peterson. The Yampa arcade. In Haskell Workshop, Haskell '03, pages 7--18. ACM, August 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. C. Elliott and P. Hudak. Functional reactive animation. In International Conference on Functional Programming, pages 263--273. ACM, June 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. C. Elliott, G. Schechter, R. Yeung, and S. Abi-Ezzi. TBAG: A high level framework for interactive, animated 3D graphics applications. In 21st Conference on Computer Graphics and Interactive Techniques, pages 421--434. ACM, July 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. T. Gautier, P. L. Guernic, and L. Besnard. Signal: A declarative language for synchronous programming of real-time systems. In Functional Programming Languages and Computer Architecture, volume 274 of Lecture Notes in Computer Science, pages 257--277. Springer-Verlag, November 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. J.-Y. Girard. Linear logic. Theoretical Computer Science, 50 (1): 1--102, 1987. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. C. Hawblitzel. Linear types for aliased resources (extended version). Technical Report MSR-TR-2005-141, Microsoft Research, Redmond, WA, October 2005.Google ScholarGoogle Scholar
  12. P. Hudak. The Haskell School of Expression - Learning Functional Programming through Multimedia. Cambridge University Press, New York, NY, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. P. Hudak. The Haskell School of Music - from Signals to Symphonies. {Version 2.0}, January 2011. URL http://haskell.cs.yale.edu/?p=112.Google ScholarGoogle Scholar
  14. P. Hudak, S. Peyton Jones, and P. Wadler (editors). Report on the Programming Language Haskell, A Non-strict Purely Functional Language (Version 1.2). ACM SIGPLAN Notices, 27 (5), May 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. P. Hudak, A. Courtney, H. Nilsson, and J. Peterson. Arrows, robots, and functional reactive programming. In Summer School on Advanced Functional Programming 2002, Oxford University, volume 2638 of Lecture Notes in Computer Science, pages 159--187. Springer-Verlag, August 2003.Google ScholarGoogle Scholar
  16. J. Hughes. Generalising monads to arrows. Science of Computer Programming, 37 (1-3): 67--111, May 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. A. Jeffrey. LTL types FRP: Linear-time temporal logic propositions as types, proofs as functional reactive programs. In Sixth Workshop on Programming Languages meets Program Verification, pages 49--60. ACM, January 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. W. Jeltsch. Towards a common categorical semantics for linear-time temporal logic and functional reactive programming. In 28th Conference on the Mathematical Foundations of Programming Semantics, pages 215--228. Elsevier, June 2012.Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. O Kiselyov, R. Lämmel, and K. Schupke. Strongly Typed Heterogeneous Collections. CWI Technical Report SEN-E 0420, CWI, August 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. N. R. Krishnaswami, N. Benton, and J. Hoffmann. Higher-Order Functional Reactive Programming in Bounded Space. In 39th Symposium on Principles of Programming Languages, pages 45--58. ACM, January 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. J. Launchbury and S. Peyton Jones. Lazy functional state threads. In Conference on Programming Language Design and Implementation, pages 24--35. ACM, June 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. S. Lindley, P. Wadler, and J. Yallop. The arrow calculus. Journal of Functional Programming, 20 (1): 51--69, January 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. H. Liu, E. Cheng, and P. Hudak. Causal commutative arrows. Journal of Functional Programming, 21 (4--5): 467--496, September 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. P. Liu and P. Hudak. Plugging a space leak with an arrow. Electronic Notes in Theoretical Computer Science, 193 (1): 29--45, November 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. E. Moggi. Computational lambda-calculus and monads. In Symposium on Logic in Computer Science, pages 14--23. IEEE, June 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. R. Paterson. A new notation for arrows. In Sixth International Conference on Functional Programming, pages 229--240. ACM, September 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. S. Peyton Jones and P. Wadler. Imperative functional programming. In 20th Symposium on Principles of Programming Languages. ACM, January 1993. 71--84. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. S. Peyton Jones et al. The Haskell 98 language and libraries: The revised report. Journal of Functional Programming, 13 (1): 0--255, January 2003.Google ScholarGoogle Scholar
  29. R. Plasmeijer and M. van Eekelen. Clean - version 2.1 language report. Technical report, Department of Software Technology, University of Nijmegen, November 2002.Google ScholarGoogle Scholar
  30. J. A. Tov and R. Pucella. Practical affine types. In 38th Symposium on Principles of Programming Languages, pages 447--458. ACM, January 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. A. Voellmy and P. Hudak. Nettle: Taking the sting out of programming network routers. In Practical Aspects of Declarative Languages, volume 6539 of Lecture Notes in Computer Science. Springer-Verlag, January 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. P. Wadler. Linear types can change the world! In Working Conference on Programming Concepts and Methods, pages 347--359. IFIP TC 2, April 1990.Google ScholarGoogle Scholar
  33. P. Wadler. Is there a use for linear logic? In Symposium on Partial Evaluation and Semantics Based Program Manipulation, pages 255--273. ACM, September 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. P. Wadler. The essence of functional programming. In 19th Symposium on Principles of Programming languages, pages 1--14. ACM, January 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. D. Winograd-Cort, H. Liu, and P. Hudak. Virtualizing Real-World Objects in FRP. In Practical Aspects of Declarative Languages, volume 7149 of Lecture Notes in Computer Science, pages 227--241. Springer-Verlag, January 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. B. A. Yorgey, S. Weirich, J. Cretin, S. Peyton Jones, D. Vytiniotis, and J. P. Magalhães. Giving Haskell a Promotion. In 8th Workshop on Types in Language Design and Implementation, pages 53--66. ACM, January 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Wormholes: introducing effects to FRP

        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

        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!