netwire-5.0.1: Functional reactive programming library

Copyright(c) 2013 Ertugrul Soeylemez
LicenseBSD3
MaintainerErtugrul Soeylemez <es@ertes.de>
Safe HaskellNone
LanguageHaskell2010

Control.Wire.Switch

Contents

Description

 

Synopsis

Simple switching

(-->) :: Monad m => Wire s e m a b -> Wire s e m a b -> Wire s e m a b infixr 1 Source

Acts like the first wire until it inhibits, then switches to the second wire. Infixr 1.

  • Depends: like current wire.
  • Inhibits: after switching like the second wire.
  • Switch: now.

(>--) :: Monad m => Wire s e m a b -> Wire s e m a b -> Wire s e m a b infixr 1 Source

Acts like the first wire until the second starts producing, at which point it switches to the second wire. Infixr 1.

  • Depends: like current wire.
  • Inhibits: after switching like the second wire.
  • Switch: now.

Context switching

modes Source

Arguments

:: (Monad m, Ord k) 
=> k

Initial mode.

-> (k -> Wire s e m a b)

Select wire for given mode.

-> Wire s e m (a, Event k) b 

Route the left input signal based on the current mode. The right input signal can be used to change the current mode. When switching away from a mode and then switching back to it, it will be resumed. Freezes time during inactivity.

  • Complexity: O(n * log n) space, O(log n) lookup time on switch wrt number of started, inactive modes.
  • Depends: like currently active wire (left), now (right).
  • Inhibits: when active wire inhibits.
  • Switch: now on mode change.

Event-based switching

Intrinsic

switch :: (Monad m, Monoid s) => Wire s e m a (b, Event (Wire s e m a b)) -> Wire s e m a b Source

Intrinsic switch: Start with the given wire. As soon as its event occurs, switch to the wire in the event's value.

  • Inhibits: like argument wire until switch, then like the new wire.
  • Switch: once, now, restart state.

dSwitch :: Monad m => Wire s e m a (b, Event (Wire s e m a b)) -> Wire s e m a b Source

Intrinsic switch: Delayed version of switch.

  • Inhibits: like argument wire until switch, then like the new wire.
  • Switch: once, after now, restart state.

Intrinsic continuable

kSwitch :: (Monad m, Monoid s) => Wire s e m a b -> Wire s e m (a, b) (Event (Wire s e m a b -> Wire s e m a b)) -> Wire s e m a b Source

Intrinsic continuable switch: kSwitch w1 w2 starts with w1. Its signal is received by w2, which may choose to switch to a new wire. Passes the wire we are switching away from to the new wire, such that it may be reused in it.

  • Inhibits: like the first argument wire, like the new wire after switch. Inhibition of the second argument wire is ignored.
  • Switch: once, now, restart state.

dkSwitch :: Monad m => Wire s e m a b -> Wire s e m (a, b) (Event (Wire s e m a b -> Wire s e m a b)) -> Wire s e m a b Source

Intrinsic continuable switch: Delayed version of kSwitch.

  • Inhibits: like the first argument wire, like the new wire after switch. Inhibition of the second argument wire is ignored.
  • Switch: once, after now, restart state.

Extrinsic

rSwitch :: Monad m => Wire s e m a b -> Wire s e m (a, Event (Wire s e m a b)) b Source

Extrinsic switch: Start with the given wire. Each time the input event occurs, switch to the wire it carries.

  • Inhibits: like the current wire.
  • Switch: recurrent, now, restart state.

drSwitch :: Monad m => Wire s e m a b -> Wire s e m (a, Event (Wire s e m a b)) b Source

Extrinsic switch: Delayed version of rSwitch.

  • Inhibits: like the current wire.
  • Switch: recurrent, after now, restart state.

alternate :: Monad m => Wire s e m a b -> Wire s e m a b -> Wire s e m (a, Event x) b Source

Acts like the first wire until an event occurs then switches to the second wire. Behaves like this wire until the event occurs at which point a *new* instance of the first wire is switched to.

  • Depends: like current wire.
  • Inhibits: like the argument wires.
  • Switch: once, now, restart state.

Extrinsic continuable

krSwitch :: Monad m => Wire s e m a b -> Wire s e m (a, Event (Wire s e m a b -> Wire s e m a b)) b Source

Extrinsic continuable switch. This switch works like rSwitch, except that it passes the wire we are switching away from to the new wire.

  • Inhibits: like the current wire.
  • Switch: recurrent, now, restart state.

dkrSwitch :: Monad m => Wire s e m a b -> Wire s e m (a, Event (Wire s e m a b -> Wire s e m a b)) b Source

Extrinsic continuable switch. Delayed version of krSwitch.

  • Inhibits: like the current wire.
  • Switch: recurrent, after now, restart state.