reactive-banana-1.2.0.0: 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

Instances

Functor Event Source # 

Methods

fmap :: (a -> b) -> Event a -> Event b #

(<$) :: a -> Event b -> Event a #

Show a => Show (Event a) Source # 

Methods

showsPrec :: Int -> Event a -> ShowS #

show :: Event a -> String #

showList :: [Event a] -> ShowS #

newtype Behavior a Source #

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

Constructors

B 

Fields

Instances

Functor Behavior Source # 

Methods

fmap :: (a -> b) -> Behavior a -> Behavior b #

(<$) :: a -> Behavior b -> Behavior a #

Applicative Behavior Source # 

Methods

pure :: a -> Behavior a #

(<*>) :: Behavior (a -> b) -> Behavior a -> Behavior b #

liftA2 :: (a -> b -> c) -> Behavior a -> Behavior b -> Behavior c #

(*>) :: Behavior a -> Behavior b -> Behavior b #

(<*) :: Behavior a -> Behavior b -> Behavior a #

Show a => Show (Behavior a) Source # 

Methods

showsPrec :: Int -> Behavior a -> ShowS #

show :: Behavior a -> String #

showList :: [Behavior a] -> ShowS #

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

Instances

Monad Moment Source # 

Methods

(>>=) :: Moment a -> (a -> Moment b) -> Moment b #

(>>) :: Moment a -> Moment b -> Moment b #

return :: a -> Moment a #

fail :: String -> Moment a #

Functor Moment Source # 

Methods

fmap :: (a -> b) -> Moment a -> Moment b #

(<$) :: a -> Moment b -> Moment a #

MonadFix Moment Source # 

Methods

mfix :: (a -> Moment a) -> Moment a #

Applicative Moment Source # 

Methods

pure :: a -> Moment a #

(<*>) :: Moment (a -> b) -> Moment a -> Moment b #

liftA2 :: (a -> b -> c) -> Moment a -> Moment b -> Moment c #

(*>) :: Moment a -> Moment b -> Moment b #

(<*) :: Moment a -> Moment b -> Moment a #

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

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

Higher-order