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
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsNotes
- 1.
fold † is marked with † for clarity since a variant named fold is introduced in Sect. 2.
- 2.
- 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.
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.
To keep the code concise we ignore the inefficient string operations here.
- 6.
- 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
Acar, U.A., Blelloch, G.E., Harper, R.: Adaptive functional programming. TOPLAS 28(6), 990–1034 (2006)
Acar, U.A., Blume, M., Donham, J.: A consistent semantics of self-adjusting computation. J. Funct. Program. 23(03), 249–292 (2013)
Blackheath, S.: Denotational semantics for Sodium (2015). http://blog.reactiveprogramming.org/?p=236
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)
Czaplicki, E., Chong, S.: Asynchronous functional reactive programming for GUIs. In: PLDI, pp. 411–422. ACM (2013)
Elliott, C., Hudak, P.: Functional reactive animation. In: ICFP, pp. 263–273. ACM (1997)
Elliott, C.M.: Push-pull functional reactive programming. In: Haskell, pp. 25–36. ACM (2009)
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
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)
Jeltsch, W.: Signals, Not Generators!. Trends Funct. Program. 10, 145–160 (2009)
Jeltsch, W.: Strongly typed and efficient functional reactive programming. Ph.D. thesis, Universitätsbibliothek (2011)
Jeltsch, W.: Grapefruit-frp: functional reactive programming core (2012). https://hackage.haskell.org/package/grapefruit-frp
Krishnaswami, N.R.: Higher-order functional reactive programming without spacetime leaks. In: ICFP, vol. 48, pp. 221–232. ACM (2013)
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
Maier, I., Rompf, T., Odersky, M.: Deprecating the observer pattern. Technical report (2010)
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)
Prokopec, A., Haller, P., Odersky, M.: Containers and aggregates, mutators and isolates for reactive programming. In: SCALA, pp. 51–61. ACM (2014)
Pugh, W., Teitelbaum, T.: Incremental computation via function caching. In: POPL, pp. 315–328. ACM (1989)
Reynders, B., Devriese, D., Piessens, F.: Multi-tier functional reactive programming for the web. In: Onward!, pp. 55–68. ACM (2014)
Salvaneschi, G., Hintz, G., Mezini, M.: REScala: Bridging between object-oriented and functional style in reactive applications. In: Modularity, pp. 25–36. ACM (2014)
van der Ploeg, A.: Monadic functional reactive programming. In: Haskell, vol. 48(12), pp. 117–128 (2014)
van der Ploeg, A., Claessen, K.: Practical principled FRP: forget the past, change the future, FRPNow! In: ICFP, pp. 302–314. ACM (2015)
Wan, Z., Taha, W., Hudak, P.: Real-time FRP. In: ICFP, pp. 146–156. ACM (2001)
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
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2017 Springer International Publishing AG
About this paper
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)