# 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

### #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.

### #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 (⍺ * _)
```

### #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)
```