Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In pure functional programming, there are no side-effects. For many types of software (for example, anything with user interaction) side-effects are necessary at some level.</p> <p>One way to get side-effect like behavior while still retaining a functional style is to use functional reactive programming. This is the combination of functional programming, and reactive programming. (The Wikipedia article you linked to is about the latter.)</p> <p>The basic idea behind reactive programming is that there are certain datatypes that represent a value "over time". Computations that involve these changing-over-time values will themselves have values that change over time.</p> <p>For example, you could represent the mouse coordinates as a pair of integer-over-time values. Let's say we had something like (this is pseudo-code):</p> <pre><code>x = &lt;mouse-x&gt;; y = &lt;mouse-y&gt;; </code></pre> <p>At any moment in time, x and y would have the coordinates of the mouse. Unlike non-reactive programming, we only need to make this assignment once, and the x and y variables will stay "up to date" automatically. This is why reactive programming and functional programming work so well together: reactive programming removes the need to mutate variables while still letting you do a lot of what you could accomplish with variable mutations.</p> <p>If we then do some computations based on this the resulting values will also be values that change over time. For example:</p> <pre><code>minX = x - 16; minY = y - 16; maxX = x + 16; maxY = y + 16; </code></pre> <p>In this example, <code>minX</code> will always be 16 less than the x coordinate of the mouse pointer. With reactive-aware libraries you could then say something like:</p> <pre><code>rectangle(minX, minY, maxX, maxY) </code></pre> <p>And a 32x32 box will be drawn around the mouse pointer and will track it wherever it moves.</p> <p>Here is a pretty good <a href="http://www.cs.brown.edu/research/pubs/techreports/reports/CS-03-20.html" rel="noreferrer">paper on functional reactive programming</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload