Module

FRP.Behavior

Package
purescript-behaviors
Repository
paf31/purescript-behaviors

#ABehavior Source

newtype ABehavior event a

ABehavior is the more general type of Behavior, which is parameterized over some underlying event type.

Normally, you should use Behavior instead, but this type can also be used with other types of events, including the ones in the Semantic module.

Instances

#Behavior Source

type Behavior = ABehavior Event

A Behavior acts like a continuous function of time.

We can construct a sample a Behavior from some Event, combine Behaviors using Applicative, and sample a final Behavior on some other Event.

#behavior Source

behavior :: forall a event. (forall b. event (a -> b) -> event b) -> ABehavior event a

Construct a Behavior from its sampling function.

#step Source

step :: forall a event. IsEvent event => a -> event a -> ABehavior event a

Create a Behavior which is updated when an Event fires, by providing an initial value.

#unfold Source

unfold :: forall b a event. IsEvent event => (a -> b -> b) -> event a -> b -> ABehavior event b

Create a Behavior which is updated when an Event fires, by providing an initial value and a function to combine the current value with a new event to create a new value.

#sample Source

sample :: forall b a event. ABehavior event a -> event (a -> b) -> event b

Sample a Behavior on some Event.

#sampleBy Source

sampleBy :: forall c b a event. IsEvent event => (a -> b -> c) -> ABehavior event a -> event b -> event c

Sample a Behavior on some Event by providing a combining function.

#sample_ Source

sample_ :: forall b a event. IsEvent event => ABehavior event a -> event b -> event a

Sample a Behavior on some Event, discarding the event's values.

#switcher Source

switcher :: forall a. Behavior a -> Event (Behavior a) -> Behavior a

Switch Behaviors based on an Event.

#gateBy Source

gateBy :: forall a p event. IsEvent event => (p -> a -> Boolean) -> ABehavior event p -> event a -> event a

Sample a Behavior on some Event by providing a predicate function.

#gate Source

gate :: forall a event. IsEvent event => ABehavior event Boolean -> event a -> event a

Filter an Event by the boolean value of a Behavior.

#integral Source

integral :: forall t a event. IsEvent event => Field t => Semiring a => (((a -> t) -> t) -> a) -> a -> ABehavior event t -> ABehavior event a -> ABehavior event a

Integrate with respect to some measure of time.

This function approximates the integral using the trapezium rule at the implicit sampling interval.

The Semiring a should be a vector field over the field t. To represent this, the user should provide a grate which lifts a multiplication function on t to a function on a. Simple examples where t ~ a can use the integral' function instead.

#integral' Source

integral' :: forall t event. IsEvent event => Field t => t -> ABehavior event t -> ABehavior event t -> ABehavior event t

Integrate with respect to some measure of time.

This function is a simpler version of integral where the function being integrated takes values in the same field used to represent time.

#derivative Source

derivative :: forall t a event. IsEvent event => Field t => Ring a => (((a -> t) -> t) -> a) -> ABehavior event t -> ABehavior event a -> ABehavior event a

Differentiate with respect to some measure of time.

This function approximates the derivative using a quotient of differences at the implicit sampling interval.

The Semiring a should be a vector field over the field t. To represent this, the user should provide a grate which lifts a division function on t to a function on a. Simple examples where t ~ a can use the derivative' function.

#derivative' Source

derivative' :: forall t event. IsEvent event => Field t => ABehavior event t -> ABehavior event t -> ABehavior event t

Differentiate with respect to some measure of time.

This function is a simpler version of derivative where the function being differentiated takes values in the same field used to represent time.

#fixB Source

fixB :: forall a. a -> (ABehavior Event a -> ABehavior Event a) -> ABehavior Event a

Compute a fixed point

#solve Source

solve :: forall a t. Field t => Semiring a => (((a -> t) -> t) -> a) -> a -> Behavior t -> (Behavior a -> Behavior a) -> Behavior a

Solve a first order differential equation of the form

da/dt = f a

by integrating once (specifying the initial conditions).

For example, the exponential function with growth rate :

exp = solve' 1.0 Time.seconds (⍺ * _)

#solve' Source

solve' :: forall a. Field a => a -> Behavior a -> (Behavior a -> Behavior a) -> Behavior a

Solve a first order differential equation.

This function is a simpler version of solve where the function being integrated takes values in the same field used to represent time.

#solve2 Source

solve2 :: forall a t. Field t => Semiring a => (((a -> t) -> t) -> a) -> a -> a -> Behavior t -> (Behavior a -> Behavior a -> Behavior a) -> Behavior a

Solve a second order differential equation of the form

d^2a/dt^2 = f a (da/dt)

by integrating twice (specifying the initial conditions).

For example, an (damped) oscillator:

oscillate = solve2' 1.0 0.0 Time.seconds (\x dx -> -⍺ * x - δ * dx)

#solve2' Source

solve2' :: forall a. Field a => a -> a -> Behavior a -> (Behavior a -> Behavior a -> Behavior a) -> Behavior a

Solve a second order differential equation.

This function is a simpler version of solve2 where the function being integrated takes values in the same field used to represent time.

#animate Source

animate :: forall eff scene. ABehavior Event scene -> (scene -> Eff (frp :: FRP | eff) Unit) -> Eff (frp :: FRP | eff) (Eff (frp :: FRP | eff) Unit)

Animate a Behavior by providing a rendering function.