netwire-5.0.3: Functional reactive programming library

Copyright | (c) 2013 Ertugrul Soeylemez
License | BSD3
Maintainer | Ertugrul Soeylemez <es@ertes.de>
Safe Haskell | None
Language | Haskell2010

Control.Wire.Switch

Contents

- Simple switching
- Context switching
- Event-based switching
  - Intrinsic
  - Intrinsic continuable
  - Extrinsic
  - Extrinsic continuable

Description

Synopsis

- (-->) :: forall (m :: Type -> Type) s e a b. Monad m => Wire s e m a b -> Wire s e m a b -> Wire s e m a b
- (>--) :: forall (m :: Type -> Type) s e a b. Monad m => Wire s e m a b -> Wire s e m a b -> Wire s e m a b
- modes :: forall (m :: Type -> Type) k s e a b. (Monad m, Ord k) => k -> (k -> Wire s e m a b) -> Wire s e m (a, Event k) b
- switch :: forall (m :: Type -> Type) s e a b. (Monad m, Monoid s) => Wire s e m a (b, Event (Wire s e m a b)) -> Wire s e m a b
- dSwitch :: forall (m :: Type -> Type) s e a b. Monad m => Wire s e m a (b, Event (Wire s e m a b)) -> Wire s e m a b
- kSwitch :: forall (m :: Type -> Type) s e a b. (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
- dkSwitch :: forall (m :: Type -> Type) s e a b. 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
- rSwitch :: forall (m :: Type -> Type) s e a b. Monad m => Wire s e m a b -> Wire s e m (a, Event (Wire s e m a b)) b
- drSwitch :: forall (m :: Type -> Type) s e a b. Monad m => Wire s e m a b -> Wire s e m (a, Event (Wire s e m a b)) b
- alternate :: forall (m :: Type -> Type) s e a b x. Monad m => Wire s e m a b -> Wire s e m a b -> Wire s e m (a, Event x) b
- krSwitch :: forall (m :: Type -> Type) s e a b. 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
- dkrSwitch :: forall (m :: Type -> Type) s e a b. 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

# Simple switching

(-->) :: forall (m :: Type -> Type) s e a b. 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.

(>--) :: forall (m :: Type -> Type) s e a b. 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

:: forall (m :: Type -> Type) k s e a b. (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 :: forall (m :: Type -> Type) s e a b. (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 :: forall (m :: Type -> Type) s e a b. 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 :: forall (m :: Type -> Type) s e a b. (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 :: forall (m :: Type -> Type) s e a b. 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 :: forall (m :: Type -> Type) s e a b. 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 :: forall (m :: Type -> Type) s e a b. 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 :: forall (m :: Type -> Type) s e a b x. 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 :: forall (m :: Type -> Type) s e a b. 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 :: forall (m :: Type -> Type) s e a b. 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.