A Functional Reactive Programming Language for Small-Scale Embedded Systems with Recursive Data Types

We introduce a new type system to Emfrp, a functional reactive programming (FRP) language designed for resource-constrained embedded systems. Functional reactive programming is a programming paradigm that allows concise descriptions of reactive systems such as GUIs by combining time-varying values that express values changing over time. Emfrp is a domain-specific language based on FRP, designed and developed for small-scale embedded systems. Because the language can statically determine the amount of runtime memory and guarantee the termination of reactive actions, a program written in Emfrp can safely continue reactive behaviors in resource-constrained environments. To ensure these properties, Emfrp disallows the use of recursive data types and functions. However, such restrictions often impose unnatural representations of data structures like lists or trees. The declarative characteristic of FRP and these restrictions impel us to write poorly maintainable redundant codes or deter us from writing certain types of programs. In this paper, we propose Emfrp, an extended Emfrp with size-annotated recursive data types, to overcome this problem. The proposed system is more expressive than Emfrp, yet, it retains the aforementioned static properties. After explaining that through examples, we describe the features of Emfrp, formalize the language, present an algorithm for statically computing the runtime memory bounds, and prove its soundness. Moreover, we implemented a compiler from Emfrp to C, measured the translation time, and evaluated runtime overhead.

[1]  Martin Hofmann,et al.  Static prediction of heap space usage for first-order functional programs , 2003, POPL '03.

[2]  Reinhold Heckmann,et al.  Towards formally verifiable resource bounds for real-time embedded systems , 2006, SIGBED.

[3]  Martin Hofmann,et al.  "Carbon Credits" for Resource-Bounded Computations Using Amortised Analysis , 2009, FM.

[4]  Paul Hudak,et al.  Functional reactive animation , 1997, ICFP '97.

[5]  Amr Sabry,et al.  Proving the correctness of reactive systems using sized types , 1996, POPL '96.

[6]  Patrick Maxim Rondon,et al.  Liquid types , 2008, PLDI '08.

[7]  Frank Pfenning,et al.  Eliminating array bound checking through dependent types , 1998, PLDI.

[8]  Chris Okasaki,et al.  Purely functional data structures , 1998 .

[9]  Nick Benton,et al.  Higher-order functional reactive programming in bounded space , 2012, POPL '12.

[10]  Mads Tofte,et al.  Region-based Memory Management , 1997, Inf. Comput..

[11]  Stephen Chong,et al.  Asynchronous functional reactive programming for GUIs , 2013, PLDI.

[12]  Nikolaj Bjørner,et al.  Z3: An Efficient SMT Solver , 2008, TACAS.

[13]  Martin Elsman,et al.  Futhark: purely functional GPU-programming with nested parallelism and in-place array updates , 2017, PLDI.

[14]  Kevin Hammond,et al.  Inferring Cost Equations for Recursive, Polymorphic and Higher-Order Functional Programs , 2003, IFL.

[15]  Takuo Watanabe,et al.  Emfrp: a functional reactive programming language for small-scale embedded systems , 2016, MODULARITY.

[16]  Ankush Das,et al.  Towards automatic resource bound analysis for OCaml , 2016, POPL.

[17]  Wolfgang De Meuter,et al.  A survey on reactive programming , 2013, CSUR.

[18]  John Hughes,et al.  Recursion and dynamic data-structures in bounded space: towards embedded ML programming , 1999, ICFP '99.

[19]  Paul Hudak,et al.  Arrows, Robots, and Functional Reactive Programming , 2002, Advanced Functional Programming.

[20]  Christoph Zenger,et al.  Indexed Types , 1997, Theoretical Computer Science.

[21]  Greg J. Michaelson,et al.  Predictable Space Behaviour in FSM-Hume , 2002, IFL.

[22]  Greg J. Michaelson,et al.  Hume: A Domain-Specific Language for Real-Time Embedded Systems , 2003, GPCE.

[23]  Samuel Z. Guyer,et al.  Juniper: a functional reactive programming language for the Arduino , 2016, FARM@ICFP.

[24]  Pascal Raymond,et al.  The synchronous data flow programming language LUSTRE , 1991, Proc. IEEE.

[25]  Annabelle McIver,et al.  LPAR-20. 20th International Conferences on Logic for Programming, Artificial Intelligence and Reasoning - Short Presentations , 2015 .