skip to main content
research-article

Safe functional reactive programming through dependent types

Published:31 August 2009Publication History
Skip Abstract Section

Abstract

Functional Reactive Programming (FRP) is an approach to reactive programming where systems are structured as networks of functions operating on signals. FRP is based on the synchronous data-flow paradigm and supports both continuous-time and discrete-time signals (hybrid systems). What sets FRP apart from most other languages for similar applications is its support for systems with dynamic structure and for higher-order reactive constructs.

Statically guaranteeing correctness properties of programs is an attractive proposition. This is true in particular for typical application domains for reactive programming such as embedded systems. To that end, many existing reactive languages have type systems or other static checks that guarantee domain-specific properties, such as feedback loops always being well-formed. However, they are limited in their capabilities to support dynamism and higher-order data-flow compared with FRP. Thus, the onus of ensuring such properties of FRP programs has so far been on the programmer as established static techniques do not suffice.

In this paper, we show how dependent types allow this concern to be addressed. We present an implementation of FRP embedded in the dependently-typed language Agda, leveraging the type system of the host language to craft a domain-specific (dependent) type system for FRP. The implementation constitutes a discrete, operational semantics of FRP, and as it passes the Agda type, coverage, and termination checks, we know the operational semantics is total, which means our type system is safe.

Skip Supplemental Material Section

Supplemental Material

safefunctionalreactiveprogrammingthroughdependenttypes.mp4

References

  1. Albert Benveniste, Paul Caspi, Stephen Edwards, Nicolas Halbwachs, Paul Le Guernic, and Robert de Simone. The synchronous languages twelve years later. Proceedings of the IEEE, Special issue on embedded systems, 91(1):64--83, 2003.Google ScholarGoogle ScholarCross RefCross Ref
  2. Gerard Berry and Georges Gonthier. The Esterel synchronous programming language: Design, semantics, implementation. Science of Computer Programming, 19(2):87--152, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Paul Caspi and Marc Pouzet. Synchronous Kahn networks. In International Conference on Functional Programming (ICFP '96), pages 226--238. ACM, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Mun Hon Cheong. Functional programming and 3D games. BEng thesis, University of New South Wales, Sydney, Australia, 2005.Google ScholarGoogle Scholar
  5. Jean-Louis Colaco, Alain Girault, Gregoire Hamon, and Marc Pouzet. Towards a higher-order synchronous data-flow language. In Embedded Software (EMSOFT '04), pages 230--239. ACM, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Gregory H. Cooper and Shriram Krishnamurthi. Embedding dynamic dataflow in a call-by-value language. In European Symposium on Programming (ESOP '06), pages 294--308. Springer-Verlag, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Antony Courtney and Conal Elliott. Genuinely functional user interfaces. In Haskell Workshop (Haskell '01), pages 41--69. Elsevier, 2001.Google ScholarGoogle Scholar
  8. Antony Courtney, Henrik Nilsson, and John Peterson. The Yampa arcade. In Haskell Workshop (Haskell '03), pages 7--18. ACM, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Conal Elliott. Simply efficient functional reactivity. http://conal.net/papers/simply-reactive/, 2008.Google ScholarGoogle Scholar
  10. Conal Elliott and Paul Hudak. Functional reactive animation. In International Conference on Functional Programming (ICFP '97), pages 263--273. ACM, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. George Giorgidze and Henrik Nilsson. Embedding a functional hybrid modelling language in Haskell. In Implementation and Application of Functional Languages (IFL '08), 2008a. To appear.Google ScholarGoogle Scholar
  12. George Giorgidze and Henrik Nilsson. Switched-on Yampa: Declarative programming of modular synthesizers. In Practical Aspects of Declarative Languages (PADL '08), pages 282--298. Springer-Verlag, 2008b. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Nicolas Halbwachs. Synchronous Programming of Reactive Systems. The Springer International Series in Engineering and Computer Science. Springer-Verlag, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Nicolas Halbwachs. Synchronous programming of reactive systems, a tutorial and commented bibliography. In Computer Aided Verification (CAV '98), pages 1--16. Springer-Verlag, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Nicolas Halbwachs, Paul Caspi, Pascal Raymond, and Daniel Pilaud. The synchronous data-flow programming language Lustre. Proceedings of the IEEE, 79(9):1305--1320, 1991.Google ScholarGoogle ScholarCross RefCross Ref
  16. Thomas A. Henzinger. The theory of hybrid automata. In Logics in Computer Science (LICS '96), pages 278--292. IEEE Computer Society, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. John Hughes. Generalising monads to arrows. Science of Computer Programming, 37(1--3):67--111, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Sam Lindley, Philip Wadler, and Jeremy Yallop. The arrow calculus. Technical report, University of Edinburgh, School of Informatics, 2008.Google ScholarGoogle Scholar
  19. Geoffrey Mainland, Greg Morrisett, and Matt Welsh. Flask: Staged functional programming for sensor networks. In International Conference on Functional Programming (ICFP '08), pages 335--345. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Henrik Nilsson, Antony Courtney, and John Peterson. Functional reactive programming, continued. In Haskell Workshop (Haskell '02), pages 51--64. ACM, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Ulf Norell. Towards a Practical Programming Language Based on Dependent Type Theory. PhD thesis, Chalmers University of Technology, 2007.Google ScholarGoogle Scholar
  22. Andre Pang, Don Stewart, Sean Seefried, and Manuel M. T. Chakravarty. Plugging Haskell in. In Haskell Workshop (Haskell '04), pages 10--21. ACM, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Ross Paterson. A new notation for arrows. In International Conference on Functional Programming (ICFP '01), pages 229--240. ACM, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. John Peterson, Paul Hudak, and Conal Elliott. Lambda in motion: Controlling robots with Haskell. In Practical Aspects of Declarative Languages (PADL '99), pages 91--105. Springer-Verlag, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Benjamin C. Pierce. Types and Programming Languages. MIT Press, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Marc Pouzet. Lucid Synchrone, version 3.0: Tutorial and reference manual. Universite Paris-Sud, LRI, 2006. http://www.lri.fr/pouzet/lucid-synchrone.Google ScholarGoogle Scholar
  27. Neil Sculthorpe and Henrik Nilsson. Optimisation of dynamic, hybrid signal function networks. In Trends in Functional Programming (TFP '08), pages 97--112. Intellect, 2008.Google ScholarGoogle Scholar
  28. Simulink. Using Simulink, Version 7.3. 3 Apple Hill Drive, Natick, MA, 2009. http://www.mathworks.com.Google ScholarGoogle Scholar
  29. Simon Thompson. Type Theory and Functional Programming. Addison-Wesley, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Zhanyong Wan and Paul Hudak. Functional reactive programming from first principles. In Programming Language Design and Implementation (PLDI '00), pages 242--252. ACM, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Zhanyong Wan, Walid Taha, and Paul Hudak. Real-time FRP. In International Conference on Functional Programming (ICFP '01), pages 146--156. ACM, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Safe functional reactive programming through dependent types

        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!