Abstract
The implementation of asynchronous systems, in particular graphical user interfaces, is traditionally based on an imperative model that uses shared mutable state and callbacks. While efficient, the combination of shared mutable state and callbacks is notoriously difficult to reason about and prone to errors. Functional reactive programming (FRP) provides an elegant alternative and recent theoretical advances in modal FRP suggest that it can be efficient as well.
In this paper, we present Async Rattus, an FRP language embedded in Haskell. The distinguishing feature of Async Rattus is a modal type constructor that enables the composition of asynchronous subsystems by keeping track of each subsystem’s clock at compile time which in turn enables dynamically changing clocks at runtime. The central component of our implementation is a Haskell compiler plugin that, among other aspects, checks the stricter typing rules of Async Rattus and infers compile-time clocks. This is the first implementation of an asynchronous modal FRP language. By embedding the language in Haskell we can exploit the existing language and library ecosystem as well as rapidly experiment with new language features and library design. We hope that such experimentation with Async Rattus sparks further research in modal FRP and its applications.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
The data constructor \(\mathbin {:::}\) for \( Sig \) is written as an infix operator, similarly to \(\mathbin {:}\) for lists.
- 2.
Async Rattus is a strict language and all type definitions are strict by default.
- 3.
\(\mathop {\langle \$\rangle }\) is the infix notation for the function \( fmap \mathbin {::} Functor \; f \Rightarrow ( a \rightarrow b )\rightarrow f \; a \rightarrow f \; b \).
- 4.
\( Maybe' \) is a strict variant of the standard \( Maybe \) type.
References
Apfelmus, H.: Reactive banana (2011). URL https://hackage.haskell.org/package/reactive-banana
Bahr, P.: Modal FRP for all: Functional reactive programming without space leaks in Haskell. J. Funct. Program. 32, e15 (2022). ISSN 0956–7968, 1469–7653, publisher: Cambridge University Press
Bahr, P., Graulund, C.U., Møgelberg, R.E.: Simply RaTT: a fitch-style modal calculus for reactive programming without space leaks. Proc. ACM Program. Lang. 3(ICFP), 1–27 (2019)
Bahr, P., Graulund, C.U., Møgelberg, R.E.: Diamonds are not forever: liveness in reactive programming with guarded recursion. Proc. ACM Program. Lang. 5(POPL), 1–28 (2021). 00002
Bahr, P., Møgelberg, R.E.: Asynchronous modal FRP. Proc. ACM Program. Lang. 7(ICFP), 476–510 (2023)
Berry, G., Cosserat, L.: The ESTEREL synchronous programming language and its mathematical semantics. In: Brookes, S.D., Roscoe, A.W., Winskel, G. (eds.) CONCURRENCY 1984. LNCS, vol. 197, pp. 389–448. Springer, Heidelberg (1985). https://doi.org/10.1007/3-540-15670-4_19 ISBN 978-3-540-39593-5
Blackheath, S.: Sodium (2012). URL https://hackage.haskell.org/package/sodium
Bärenz, M., Perez, I.: Rhine: FRP with type-level clocks. In: Proceedings of the 11th ACM SIGPLAN International Symposium on Haskell, Haskell 2018, pp. 145–157. Association for Computing Machinery, New York (2018). ISBN 978-1-4503-5835-4
Caspi, P., Pilaud, D., Halbwachs, N., Plaice, J.A.: LUSTRE: a declarative language for real-time programming. In: Proceedings of the 14th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, POPL ’87, pp. 178–188. ACM, New York (1987). ISBN 0-89791-215-2
Cave, A., Ferreira, F., Panangaden, P., Pientka, B.: Fair Reactive Programming. In: Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’14, pp. 361–372. ACM, San Diego (2014). ISBN 978-1-4503-2544-8
Clouston, R.: Fitch-style modal lambda calculi. In: Baier, C., Dal Lago, U. (eds.) FoSSaCS 2018. LNCS, vol. 10803, pp. 258–275. Springer, Cham (2018). https://doi.org/10.1007/978-3-319-89366-2_14
Diatchki, I.S.: Improving Haskell types with SMT. In: Proceedings of the 2015 ACM SIGPLAN Symposium on Haskell, Haskell ’15, pp. 1–10. Association for Computing Machinery (2015)
Elliott, C.: Compiling to categories. Proc. ACM Program. Lang. 1(ICFP), 1–27 (2017)
Elliott, C., Hudak, P.: Functional reactive animation. In: Proceedings of the Second ACM SIGPLAN International Conference on Functional Programming, ICFP ’97, pp. 263–273. ACM, New York (1997). ISBN 0-89791-918-1
Elliott, C.M.: Push-pull functional reactive programming. In: Proceedings of the 2Nd ACM SIGPLAN Symposium on Haskell, Haskell ’09, pp. 25–36. ACM, New York (2009). ISBN 978-1-60558-508-6, 00145 event-place: Edinburgh, Scotland
Graulund, C.U., Szamozvancev, D., Krishnaswami, N.: Adjoint reactive GUI programming. In: FoSSaCS, pp. 289–309 (2021)
Gundry, A.: A typechecker plugin for units of measure: domain-specific constraint solving in GHC Haskell. In: Proceedings of the 2015 ACM SIGPLAN Symposium on Haskell, Haskell ’15, pp. 11–22. Association for Computing Machinery, New York (2015)
Houlborg, E., Rørdam, G., Bahr, P.: Async Rattus (2023). URL https://hackage.haskell.org/package/AsyncRattus
Hudak, P., Courtney, A., Nilsson, H., Peterson, J.: Arrows, robots, and functional reactive programming. In: Jeuring, J., Jones, S.L.P. (eds.) AFP 2002. LNCS, vol. 2638, pp. 159–187. Springer, Heidelberg (2003). https://doi.org/10.1007/978-3-540-44833-4_6 ISBN 978-3-540-40132-2
Jeffrey, A.: LTL types FRP: linear-time temporal logic propositions as types, proofs as functional reactive programs. In: Claessen, K., Swamy, N. (eds.) Proceedings of the sixth workshop on Programming Languages meets Program Verification, PLPV 2012, Philadelphia, PA, USA, 24 January 2012, pp. 49–60. ACM, Philadelphia (2012). ISBN 978-1-4503-1125-0
Jeffrey, A.: Functional reactive types. In: Proceedings of the Joint Meeting of the Twenty-Third EACSL Annual Conference on Computer Science Logic (CSL) and the Twenty-Ninth Annual ACM/IEEE Symposium on Logic in Computer Science (LICS), CSL-LICS ’14, pp. 1–9. ACM, New York (2014). ISBN 978-1-4503-2886-9
Jeltsch, W.: Grapefruit (2007). URL https://hackage.haskell.org/package/grapefruit
Jeltsch, W.: Towards a common categorical semantics for linear-time temporal logic and functional reactive programming. Electr. Notes Theor. Comput. Sci. 286, 229–242 (2012)
Jeltsch, W.: Temporal logic with “until", functional reactive programming with processes, and concrete process categories. In: Proceedings of the 7th Workshop on Programming Languages Meets Program Verification, PLPV ’13, pp. 69–78. ACM, New York (2013). ISBN 978-1-4503-1860-0
Krishnaswami, N.R.: AdjS compiler (2013). URL https://github.com/neel-krishnaswami/adjs
Krishnaswami, N.R.: Higher-order functional reactive programming without spacetime leaks. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, ICFP ’13, pp. 221–232. ACM, Boston (2013). ISBN 978-1-4503-2326-0
Krishnaswami, N.R., Benton, N.: A semantic model for graphical user interfaces. In: Proceedings of the 16th ACM SIGPLAN international conference on Functional programming, ICFP ’11, pp. 45–57. Association for Computing Machinery, New York (2011). ISBN 978-1-4503-0865-6
Krishnaswami, N.R., Benton, N.: Ultrametric semantics of reactive programs. In: 2011 IEEE 26th Annual Symposium on Logic in Computer Science, pp. 257–266. IEEE Computer Society, Washington (2011). ISSN 1043–6871
Krishnaswami, N.R., Benton, N., Hoffmann, J.: Higher-order functional reactive programming in bounded space. In: Field, J., Hicks, M. (eds.) Proceedings of the 39th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2012, Philadelphia, Pennsylvania, USA, 22–28 January 2012, pp. 45–58. ACM, Philadelphia (2012). ISBN 978-1-4503-1083-3
Patai, G.: Efficient and compositional higher-order streams. In: Mariño, J. (ed.) WFLP 2010. LNCS, vol. 6559, pp. 137–154. Springer, Heidelberg (2011). https://doi.org/10.1007/978-3-642-20775-4_8
Perez, I., Bärenz, M., Nilsson, H.: Functional reactive programming, refactored. In: Proceedings of the 9th International Symposium on Haskell, Haskell 2016, pp. 33–44. Association for Computing Machinery, New York (2016). ISBN 978-1-4503-4434-0
Ploeg, A.v.d., Claessen, K.: Practical principled FRP: forget the past, change the future, FRPNow! In: Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming, ICFP 2015, pp. 302–314. Association for Computing Machinery, Vancouver (2015). ISBN 978-1-4503-3669-7, 00019
Pouzet, M.: Lucid synchrone, version 3. Tutorial and reference manual. Université Paris-Sud, LRI 1, 25 (2006)
Prott, K.O., Teegen, F., Christiansen, J.: Embedding functional logic programming in Haskell via a compiler plugin. In: Hanus, M., Inclezan, D. (eds.) Practical Aspects of Declarative Languages, pp. 37–55. Lecture Notes in Computer Science, Springer Nature Switzerland (2023). https://doi.org/10.1007/978-3-031-24841-2_3
Trinkle, R.: Reflex (2016). URL https://reflex-frp.org
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2023 The Author(s), under exclusive license to Springer Nature Switzerland AG
About this paper
Cite this paper
Bahr, P., Houlborg, E., Rørdam, G.T.S. (2023). Asynchronous Reactive Programming with Modal Types in Haskell. In: Gebser, M., Sergey, I. (eds) Practical Aspects of Declarative Languages. PADL 2024. Lecture Notes in Computer Science, vol 14512. Springer, Cham. https://doi.org/10.1007/978-3-031-52038-9_2
Download citation
DOI: https://doi.org/10.1007/978-3-031-52038-9_2
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-031-52037-2
Online ISBN: 978-3-031-52038-9
eBook Packages: Computer ScienceComputer Science (R0)