University of Oulu

Expressing functional reactive programming in C++

Saved in:
Author: Al-Khanji, Louai1
Organizations: 1University of Oulu, Faculty of Information Technology and Electrical Engineering, Department of Information Processing Science, Information Processing Science
Format: ebook
Version: published version
Access: open
Online Access: PDF Full Text (PDF, 1.4 MB)
Pages: 49
Persistent link:
Language: English
Published: Oulu : L. Al-Khanji, 2015
Publish Date: 2015-11-25
Thesis type: Master's thesis
Tutor: Vesanen, Ari
Reviewer: Vesanen, Ari
Siirtola, Antti


Most C++ programs are written in a straight-forward imperative style. While e.g. callbacks are employed either directly or through the observer pattern, the mental overhead of keeping program state congruent is high and increases with program size.

This paper presents a translation of functional reactive programming into C++ terms. This paradigm originates from the Haskell language community and seeks to express easily how programs should react to new input.

Concretely, an implementation of a reactive property class is presented, where property in this context is a class holding a value of a user-specified type. The property class provides a mechanism to bind to it an expression that takes an arbitrary number of inputs, some of which can be other instances of property classes. When any of these dependent properties is updated the expression is re-evaluated, so that a dataflow graph may be built using this type. The automatic re-evaluation reduces the boilerplate code necessary to update variables, which can lead to fewer programming errors and more concise programs.

The implementation demonstrates that the core principles of functional reactive programming can be expressed in modern C++. Further, the implementation can be done in an idiomatic manner which appears familiar to C++ developers.

At the same time, the implementation’s complexity highlights how much further the C++ meta-programming facilities must be developed to properly support facilities such as a functional reactive programming library implementation.

A number of compile-time template metaprogramming utilities used in the implementation are also introduced.

see all

Copyright information: © Louai Al-Khanji, 2015. This publication is copyrighted. You may download, display and print it for your own personal use. Commercial use is prohibited.