This repository has been archived by the owner before Nov 9, 2022. It is now read-only.
/ purescript-behaviors Public archive

A simple push-pull FRP implementation

# paf31/purescript-behaviors

Switch branches/tags
Nothing to show

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

## Files

Failed to load latest commit information.
Type
Name
Commit time

# purescript-behaviors

## Building

``````pulp build
npm run example
``````

## Introduction

Push-pull FRP is concerned with events and behaviors. Events are values which occur discretely over time, and behaviors act like continuous functions of time.

Why bother with behaviors at all, when the machines we work with deal with events such as interrupts at the most basic level?

Well, we can work with continuous functions of time in a variety of ways, including by differentiation and integration. Also, working with a conceptually infinitely-dense representation means that we can defer the choice of sampling interval until we are ready to render our results.

This library takes a slightly novel approach by constructing behaviors from events.

```newtype ABehavior event a = ABehavior (forall b. event (a -> b) -> event b)

type Behavior = ABehavior Event```

Here, a `Behavior` is constructed directly from its sampling function. The various functions which work with this representation can delay the choice of sampling interval for as long as possible, but ultimately this `Behavior` is equivalent to working with events directly, albeit with alternative, function-like instances.

This representation has the correct type class instances, and supports operations such as integration, differentiation and even recursion, which means we can use it to solve interactive differential equations. For example, here is an exponential function computed as the solution of a differential equation:

`exp = fixB 1.0 \b -> integral' 1.0 seconds ((-2.0 * _) <\$> b)`

Its differential equation is ππ₯/ππ‘ = β2π₯ , which is rearranged so the right hand side gives an expression whose fixed point solution is the exponential function desired.

π₯ = β«β2π₯ ππ‘

(In the purescript formulation, the values `1.0` are respectively the initial value for the Behavior being integrated over, and the initial approximation to the integral)

See the example project for a more interesting, interactive example.

See also a conversational demo. An accompanying video discussion breaks down a component of the example project.

A simple push-pull FRP implementation

v8.0.0 Latest
Sep 4, 2019

## Packages 0

No packages published