Haai
Reactive programming without lifting.

Getting started

In this guide, you will learn how to start a Haai session from within your browser, and how to write (and run) your first reactive program using Haai. We will be using the self-contained Haai environment that runs in a webbrowser.

 Open the editor

Once the Haai Environment is up and running, you can start typing in your code. Let's start with a simple program. Nothing out of the ordinary, just a simple reactor that will multiply numbers by two. No point in creating something complicated yet!

(defr (double n)
  (* n 2))

Enter the code in the code panel (this is the panel at the top), and press the Evaluate code button. You have now run your very first Haai program. However, nothing has really happened. The only thing you did was defining a new reactor named double with one parameter. Its behaviour has been described in the body of the reactor definition.

You can take a look at the visualisation of all the reactors that you define, by clicking on the links in the program output. Clicking on the link opens, in a new window, a visualistion of the reactor in question. This can help you in identifying problems in your code.

If you want to use your double reactor, and let it react on some time-varying data sources, you will need to deploy it. Deploying a reactor looks like a normal procedure application, as in Scheme, but instead of applying a procedure once, deploying a reactor means creating a copy of its DAG and connecting its source node with a signal.

Unfortunately, the current implementation of Haai does not support live code changes. A read-eval-print loop which allows you to incrementally construct your reactive program is on the roadmap. For now, please reload the page, and type in the following code.

(defr (double n)
  (* n 2))

(def test-a (double 4))
(def test-b (double time))

In the code above, the double reactor is deployed twice. Once on a signal that is constantly carrying the number 4, and once on the signal time. The time signal is the only signal that is built-in into the language. In the online programming environmt time increments by one each time you press the "Increment time" button that shows up after you evaluated the code. Click the button a couple of times, and note how the value carried by the test-b changes.