Safe Haskell | Safe |
---|---|
Language | Haskell98 |
- type Nat = Int
- type Time = Nat
- newtype Event a = E {}
- newtype Behavior a = B {
- unB :: [a]
- interpret :: (Event a -> Moment (Event b)) -> [Maybe a] -> [Maybe b]
- module Control.Applicative
- never :: Event a
- unionWith :: (a -> a -> a) -> Event a -> Event a -> Event a
- filterJust :: Event (Maybe a) -> Event a
- apply :: Behavior (a -> b) -> Event a -> Event b
- newtype Moment a = M {}
- accumE :: a -> Event (a -> a) -> Moment (Event a)
- stepper :: a -> Event a -> Moment (Behavior a)
- valueB :: Behavior a -> Moment a
- observeE :: Event (Moment a) -> Event a
- switchE :: Event (Event a) -> Moment (Event a)
- switchB :: Behavior a -> Event (Behavior a) -> Moment (Behavior a)
Synopsis
Model implementation for learning and testing.
Overview
This module reimplements the key FRP types and functions from the module Reactive.Banana.Combinators in a way that is hopefully easier to understand. Thereby, this model also specifies the semantics of the library. Of course, the real implementation is much more efficient than this model here.
To understand the model in detail, look at the source code! (If there is no link to the source code at every type signature, then you have to run cabal with --hyperlink-source flag.)
This model is authoritative:
Event functions that have been constructed using the same combinators
must give the same results when run with the interpret
function
from either the module Reactive.Banana.Combinators
or the module Reactive.Banana.Model.
This must also hold for recursive and partial definitions
(at least in spirit, I'm not going to split hairs over _|_
vs \_ -> _|_
).
Core Combinators
Event and Behavior
The FRP model used in this library is actually a model with continuous time.
However, it can be shown that this model is observationally equivalent to a particular model with (seemingly) discrete time steps, which is implemented here. The main reason for doing this is to be able to handle recursion correctly. Details will be explained elsewhere.
Behavior is modeled by an infinite list of values.
It is isomorphic to Time -> a
.
First-order
module Control.Applicative