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

Safe Haskell | Safe-Inferred
Language | Haskell98

Reactive.Banana.Model

Contents

- Synopsis
- Overview
- Core Combinators
  - Event and Behavior
  - First-order
  - Moment and accumulation
  - Higher-order

Synopsis

- type Nat = Int
- type Time = Nat
- newtype Event a = E {
  - unE :: [Maybe a]
  }
- 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
- mergeWith :: (a -> c) -> (b -> c) -> (a -> b -> c) -> Event a -> Event b -> Event c
- filterJust :: Event (Maybe a) -> Event a
- apply :: Behavior (a -> b) -> Event a -> Event b
- newtype Moment a = M {
  - unM :: Time -> a
  }
- 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 a -> 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

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

Instances details

Functor Event Source # |
Instance details Defined in Reactive.Banana.Model Methods fmap :: (a -> b) -> Event a -> Event b Source # (<$) :: a -> Event b -> Event a Source #
Show a => Show (Event a) Source # |
Instance details Defined in Reactive.Banana.Model Methods showsPrec :: Int -> Event a -> ShowS Source # show :: Event a -> String Source # showList :: [Event a] -> ShowS Source #

newtype Behavior a Source #

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

Constructors

B |

Fields

- unB :: [a]

#### Instances

Instances details

Applicative Behavior Source # |
Instance details Defined in Reactive.Banana.Model Methods pure :: a -> Behavior a Source # (<*>) :: Behavior (a -> b) -> Behavior a -> Behavior b Source # liftA2 :: (a -> b -> c) -> Behavior a -> Behavior b -> Behavior c Source # (*>) :: Behavior a -> Behavior b -> Behavior b Source # (<*) :: Behavior a -> Behavior b -> Behavior a Source #
Functor Behavior Source # |
Instance details Defined in Reactive.Banana.Model Methods fmap :: (a -> b) -> Behavior a -> Behavior b Source # (<$) :: a -> Behavior b -> Behavior a Source #
Show a => Show (Behavior a) Source # |
Instance details Defined in Reactive.Banana.Model Methods showsPrec :: Int -> Behavior a -> ShowS Source # show :: Behavior a -> String Source # showList :: [Behavior a] -> ShowS Source #

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

## First-order

module Control.Applicative

never :: Event a Source #

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

mergeWith :: (a -> c) -> (b -> c) -> (a -> b -> c) -> Event a -> Event b -> Event c Source #

filterJust :: Event (Maybe 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

#### Instances

Instances details

Applicative Moment Source # |
Instance details Defined in Reactive.Banana.Model Methods pure :: a -> Moment a Source # (<*>) :: Moment (a -> b) -> Moment a -> Moment b Source # liftA2 :: (a -> b -> c) -> Moment a -> Moment b -> Moment c Source # (*>) :: Moment a -> Moment b -> Moment b Source # (<*) :: Moment a -> Moment b -> Moment a Source #
Functor Moment Source # |
Instance details Defined in Reactive.Banana.Model Methods fmap :: (a -> b) -> Moment a -> Moment b Source # (<$) :: a -> Moment b -> Moment a Source #
Monad Moment Source # |
Instance details Defined in Reactive.Banana.Model Methods (>>=) :: Moment a -> (a -> Moment b) -> Moment b Source # (>>) :: Moment a -> Moment b -> Moment b Source # return :: a -> Moment a Source #
MonadFix Moment Source # |
Instance details Defined in Reactive.Banana.Model Methods mfix :: (a -> Moment a) -> Moment a Source #

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

stepper :: a -> Event a -> Moment (Behavior a) Source #

## Higher-order

valueB :: Behavior a -> Moment a Source #

observeE :: Event (Moment a) -> Event a Source #

switchE :: Event a -> Event (Event a) -> Moment (Event a) Source #

switchB :: Behavior a -> Event (Behavior a) -> Moment (Behavior a) Source #