reactive-banana-1.1.0.1: Library for functional reactive programming (FRP).

Safe HaskellSafe
LanguageHaskell98

Reactive.Banana.Model

Contents

Synopsis

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

type Nat = Int Source

Natural numbers (poorly represented).

type Time = Nat Source

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.

newtype Event a Source

Event is modeled by an infinite list of Maybe values. It is isomorphic to Time -> Maybe a.

Nothing indicates that no occurrence happens, while Just indicates that an occurrence happens.

Constructors

E 

Fields

unE :: [Maybe a]
 

Instances

newtype Behavior a Source

Behavior is modeled by an infinite list of values. It is isomorphic to Time -> a.

Constructors

B 

Fields

unB :: [a]
 

interpret :: (Event a -> Moment (Event b)) -> [Maybe a] -> [Maybe b] Source

First-order

unionWith :: (a -> a -> a) -> Event a -> Event a -> Event a Source

apply :: Behavior (a -> b) -> Event a -> Event b Source

Moment and accumulation

newtype Moment a Source

Constructors

M 

Fields

unM :: Time -> a
 

accumE :: a -> Event (a -> a) -> Moment (Event a) Source

Higher-order