Skip to main content

Efficient Functional Reactive Programming Through Incremental Behaviors

  • Conference paper
  • First Online:

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 10695))

Abstract

Many types of software are inherently event-driven ranging from web applications to embedded devices and traditionally, such applications are implemented using imperative callbacks. An alternative approach to writing such programs is functional reactive programming (FRP). FRP offers abstractions to make event-driven programming convenient, safe and composable, but they come at a price. FRP behaviors cannot efficiently deal with larger, incrementally constructed values such as a collection of messages or a list of connected devices. Since these situations occur naturally, it hinders the use of FRP. We report on a new FRP primitive: ‘incremental behavior’. We show that the semantics fit within existing FRP semantics and that their API can be used as a foundation for more ad-hoc solutions, such as incremental collections and discrete behaviors. Finally, we present benchmarks that demonstrate the advantages of incremental behaviors in terms of reduced computation time and bandwidth.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Notes

  1. 1.

    fold is marked with for clarity since a variant named fold is introduced in Sect. 2.

  2. 2.

    https://github.com/Tzbob/hokko.

  3. 3.

    Note that to have a definable semantics for \( fold \) an extra restriction on events (which we omitted for brevity) is required. The occurrences in an event must be ‘uniform discrete’, that is, the amount of events before any time \( t \) must be finite.

  4. 4.

    This construction assumes that the event fires only a finite amount of times before any fixed time t (a property we call uniform discreteness).

  5. 5.

    To keep the code concise we ignore the inefficient string operations here.

  6. 6.

    https://github.com/stacycurl/delta.

  7. 7.

    To make our benchmarks as accurate and fair as possible on the JVM, the measurements are results over multiple VM invocations, each prepared with warmup operations.

References

  1. Acar, U.A., Blelloch, G.E., Harper, R.: Adaptive functional programming. TOPLAS 28(6), 990–1034 (2006)

    Article  Google Scholar 

  2. Acar, U.A., Blume, M., Donham, J.: A consistent semantics of self-adjusting computation. J. Funct. Program. 23(03), 249–292 (2013)

    Article  MathSciNet  MATH  Google Scholar 

  3. Blackheath, S.: Denotational semantics for Sodium (2015). http://blog.reactiveprogramming.org/?p=236

  4. Cai, Y., Giarrusso, P.G., Rendel, T., Ostermann, K.: A theory of changes for higher-order languages: incrementalizing \(\lambda \)-calculi by static differentiation. In: PLDI, vol. 49, pp. 145–155. ACM (2014)

    Google Scholar 

  5. Czaplicki, E., Chong, S.: Asynchronous functional reactive programming for GUIs. In: PLDI, pp. 411–422. ACM (2013)

    Google Scholar 

  6. Elliott, C., Hudak, P.: Functional reactive animation. In: ICFP, pp. 263–273. ACM (1997)

    Google Scholar 

  7. Elliott, C.M.: Push-pull functional reactive programming. In: Haskell, pp. 25–36. ACM (2009)

    Google Scholar 

  8. Firsov, D., Jeltsch, W.: Purely functional incremental computing. In: Castor, F., Liu, Y.D. (eds.) SBLP 2016. LNCS, vol. 9889, pp. 62–77. Springer, Cham (2016). https://doi.org/10.1007/978-3-319-45279-1_5

    Chapter  Google Scholar 

  9. Hammer, M.A., Dunfield, J., Headley, K., Labich, N., Foster, J.S., Hicks, M., Van Horn, D.: Incremental computation with names. In: OOPSLA, vol. 50, pp. 748–766. ACM (2015)

    Google Scholar 

  10. Jeltsch, W.: Signals, Not Generators!. Trends Funct. Program. 10, 145–160 (2009)

    Google Scholar 

  11. Jeltsch, W.: Strongly typed and efficient functional reactive programming. Ph.D. thesis, Universitätsbibliothek (2011)

    Google Scholar 

  12. Jeltsch, W.: Grapefruit-frp: functional reactive programming core (2012). https://hackage.haskell.org/package/grapefruit-frp

  13. Krishnaswami, N.R.: Higher-order functional reactive programming without spacetime leaks. In: ICFP, vol. 48, pp. 221–232. ACM (2013)

    Google Scholar 

  14. Maier, I., Odersky, M.: Higher-order reactive programming with incremental lists. In: Castagna, G. (ed.) ECOOP 2013. LNCS, vol. 7920, pp. 707–731. Springer, Heidelberg (2013). https://doi.org/10.1007/978-3-642-39038-8_29

    Chapter  Google Scholar 

  15. Maier, I., Rompf, T., Odersky, M.: Deprecating the observer pattern. Technical report (2010)

    Google Scholar 

  16. Mitschke, R., Erdweg, S., Köhler, M., Mezini, M., Salvaneschi, G.: i3ql: language-integrated live data views. In: Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications, pp. 417–432. ACM (2014)

    Google Scholar 

  17. Prokopec, A., Haller, P., Odersky, M.: Containers and aggregates, mutators and isolates for reactive programming. In: SCALA, pp. 51–61. ACM (2014)

    Google Scholar 

  18. Pugh, W., Teitelbaum, T.: Incremental computation via function caching. In: POPL, pp. 315–328. ACM (1989)

    Google Scholar 

  19. Reynders, B., Devriese, D., Piessens, F.: Multi-tier functional reactive programming for the web. In: Onward!, pp. 55–68. ACM (2014)

    Google Scholar 

  20. Salvaneschi, G., Hintz, G., Mezini, M.: REScala: Bridging between object-oriented and functional style in reactive applications. In: Modularity, pp. 25–36. ACM (2014)

    Google Scholar 

  21. van der Ploeg, A.: Monadic functional reactive programming. In: Haskell, vol. 48(12), pp. 117–128 (2014)

    Google Scholar 

  22. van der Ploeg, A., Claessen, K.: Practical principled FRP: forget the past, change the future, FRPNow! In: ICFP, pp. 302–314. ACM (2015)

    Google Scholar 

  23. Wan, Z., Taha, W., Hudak, P.: Real-time FRP. In: ICFP, pp. 146–156. ACM (2001)

    Google Scholar 

Download references

Acknowledgments

Bob Reynders holds an SB fellowship of the Research Foundation - Flanders (FWO). Dominique Devriese holds a postdoctoral fellowship of the Research Foundation - Flanders (FWO).

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Bob Reynders .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Springer International Publishing AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

Reynders, B., Devriese, D. (2017). Efficient Functional Reactive Programming Through Incremental Behaviors. In: Chang, BY. (eds) Programming Languages and Systems. APLAS 2017. Lecture Notes in Computer Science(), vol 10695. Springer, Cham. https://doi.org/10.1007/978-3-319-71237-6_16

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-71237-6_16

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-71236-9

  • Online ISBN: 978-3-319-71237-6

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics