netwire-5.0.0: Functional reactive programming library

MaintainerErtugrul Soeylemez <es@ertes.de>
Safe HaskellNone

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 bSource

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.

Context switching

modesSource

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 bSource

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 bSource

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 bSource

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 bSource

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)) bSource

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)) bSource

Extrinsic switch: Delayed version of rSwitch.

  • Inhibits: like the current wire.
  • Switch: recurrent, after 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)) bSource

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)) bSource

Extrinsic continuable switch. Delayed version of krSwitch.

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