Module

FRP.Poll

Package
purescript-hyrule
Repository
mikesol/purescript-hyrule

#APoll Source

newtype APoll :: (Type -> Type) -> Type -> Typenewtype APoll event a

APoll is the more general type of Poll, which is parameterized over some underlying event type.

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

Instances

#Poll Source

type Poll = APoll Event

A Poll acts like a survey or poll. We get a series of questions in time of form a -> b, and we respond with b.

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

#animate Source

animate :: forall scene. APoll Event scene -> (scene -> Effect Unit) -> Effect (Effect Unit)

Animate a Poll by providing a rendering function.

#Pollable Source

class Pollable :: (Type -> Type) -> (Type -> Type) -> Constraintclass Pollable event pollable | pollable -> event where

Members

  • sample :: forall a b. APoll event a -> pollable (a -> b) -> pollable b

    Sample a Poll on some Event.

Instances

#create Source

create :: forall a. ST Global (PollIO a)

#createPure Source

createPure :: forall a. ST Global (PurePollIO a)

#deflect Source

deflect :: forall a. Poll a -> ST Global (Poll a)

#derivative Source

derivative :: forall event a t. IsEvent event => Pollable event event => Field t => Ring a => (((a -> t) -> t) -> a) -> APoll event t -> APoll event a -> APoll 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 event t. IsEvent event => Pollable event event => Field t => APoll event t -> APoll event t -> APoll 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.

#dredge Source

dredge :: forall a b event. Apply event => (event a -> event b) -> APoll event a -> APoll event b

Turn a function over events into a function over polls.

#effectToPoll Source

effectToPoll :: Effect ~> Poll

Turn an Effect into a poll

#fixB Source

fixB :: forall event a. Pollable event event => IsEvent event => a -> (APoll event a -> APoll event a) -> APoll event a

Compute a fixed point

#gate Source

gate :: forall event a. Pollable event event => Filterable event => APoll event Boolean -> event a -> event a

Filter an Event by the boolean value of a Poll.

#gateBy Source

gateBy :: forall event p a. Pollable event event => Filterable event => (p -> a -> Boolean) -> APoll event p -> event a -> event a

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

#integral Source

integral :: forall event a t. IsEvent event => Pollable event event => Field t => Semiring a => (((a -> t) -> t) -> a) -> a -> APoll event t -> APoll event a -> APoll 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 event t. IsEvent event => Pollable event event => Field t => t -> APoll event t -> APoll event t -> APoll 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.

#mailbox Source

mailbox :: forall a b. Ord a => ST Global { poll :: a -> Poll b, push :: { address :: a, payload :: b } -> Effect Unit }

#merge Source

merge :: forall a. Array (Poll a) -> Poll a

Merge together several polls. This has the same functionality as oneOf, but it is faster and less prone to stack explosions.

#mergeMap Source

mergeMap :: forall a b. (a -> Poll b) -> Array a -> Poll b

#poll Source

poll :: forall event a. (forall b. event (a -> b) -> event b) -> APoll event a

Construct a Poll from its sampling function.

#rant Source

rant :: forall a. Poll a -> ST Global { poll :: Poll a, unsubscribe :: ST Global Unit }

#refToPoll Source

refToPoll :: Ref ~> Poll

Turn a Ref into a poll

#refize Source

refize :: forall a. a -> Poll a -> Poll (Tuple (STRef Global a) a)

#sampleBy Source

sampleBy :: forall event pollable a b c. Pollable event pollable => Functor event => Functor pollable => (a -> b -> c) -> APoll event a -> pollable b -> pollable c

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

#sample_ Source

sample_ :: forall event pollable a b. Pollable event pollable => Functor event => Functor pollable => APoll event a -> pollable b -> pollable a

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

#sham Source

sham :: forall event. IsEvent event => event ~> (APoll event)

A poll where the answers are rigged by the nefarious Event a

#solve Source

solve :: forall t a. Field t => Semiring a => (((a -> t) -> t) -> a) -> a -> Poll t -> (Poll a -> Poll a) -> Poll 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 -> Poll a -> (Poll a -> Poll a) -> Poll 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 t a. Field t => Semiring a => (((a -> t) -> t) -> a) -> a -> a -> Poll t -> (Poll a -> Poll a -> Poll a) -> Poll 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 -> Poll a -> (Poll a -> Poll a -> Poll a) -> Poll 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.

#stRefToPoll Source

stRefToPoll :: (STRef Global) ~> Poll

Turn an ST Ref into a poll

#stToPoll Source

stToPoll :: (ST Global) ~> Poll

Turn an ST Global into a poll

#step Source

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

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

#switcher Source

switcher :: forall event a. Pollable event event => IsEvent event => APoll event a -> event (APoll event a) -> APoll event a

Switch Polls based on an Event.

#unfold Source

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

Create a Poll 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.