Signal
Functions
map

Applies a function f to the given input signal

Type Signature
((a) -> b, sig<a>) -> sig<b>
Parameters
f : (a) -> b

The mapping function

s : sig<a>

The input signal

Returns

The signal transformed by the mapping function

sink

Applies the function on the given signal for the purpose of performing side effects.

Type Signature
((a) -> unit, sig<a>) -> unit
Parameters
f : (a) -> unit

The function to call

s : sig<a>

The input signal

Returns

Unit

filter

Filters a signal using the given predicate function. If the function returns true, the signal is filtered and the output signal will contain nothing. If the function returns false, the signal is unfiltered and the output signal will be the same as the input signal.

Type Signature
((a') -> bool, sig<a>) -> sig<a>
Parameters
f : (a) -> bool

The predicate function

s : sig<a>

The input signal

Returns

The filtered output signal.

merge

Merges streams of the same type together. If sigA has a value, then sigA is returned. Otherwise sigB is returned.

Type Signature
merge<a>(sig<a>, sig<a>) -> sig<a>
Parameters
sigA : sig<a>

The first signal to merge

sigB : sig<b>

The second signal to merge

Returns

A signal of the two merged streams

mergeMany

Merges multiple signals together. The leftmost signal holding a value is the value held by the return signal. If none of the given signals holds a value, then the return stream will hold nothing.

Type Signature
(list<sig<a>, n>) -> sig<a>
Parameters
sigs : list<sig<a>, n>

A list of signals to merge together.

join

Joins streams of two types together. If sigA has a value, then Prelude:left is used to construct the output signal. Otherwise if sigB has a value then Prelude:right is used to construct the output signal. If neither sigA or sigB holds a value, then the output signal also holds no value.

Type Signature
(sig<a>, sig<b>) -> sig<either<a,b>>
Parameters
sigA : sig<a>

The first signal to join

sigB : sig<b>

The second signal to join

Returns

A signal of the two joined streams.

toUnit

Maps a signal of some type to a signal of units. If sig holds a value, then the output signal holds unit. Otherwise the output signal holds nothing.

Type Signature
(sig<a>) -> sig<unit>
Parameters
s : sig<a>

The signal to convert to a unit signal

Returns

A signal of units.

foldP

Creates a past dependent signal. If the incoming signal contains a value, f will be called on the value and the previous state and the return value from this function determines the new state. The state is held in the inout parameter. foldP stands for fold over the past.

Type Signature
((a, state) -> state, inout state, sig<a>) -> sig<state>
Parameters
f : (a, state) -> state

The folding function

state0 : inout state

An inout to the mutable state

incoming : sig<a>

The signal of incoming values

Returns

A signal containing the state just returned by f, or nothing if the input signal contained nothing.

dropRepeats

Drop values that have been repeated on the given signal.

Type Signature
(inout maybe<a>, sig<a>) -> sig<a>
Parameters
maybePrevValue : inout maybe<a>

A variable holding the previous value or nothing if there hasnt been a previous value yet

incoming : sig<a>

The incoming signal

Returns

A filtered signal where two values in a row will not be repeated.

latch

Constantly emmits the value held in the latch. The value held in the latch is updated if it receives a value on the incoming signal.

Type Signature
(inout a, sig<a>) -> sig<a>
Parameters
prevValue : inout a

Holds the previous values that the latch received

incoming : sig<a>

The incoming latch update signal

Returns

A signal which constantly emmits the value last received on the incoming signal.

map2

Applys a mapping function to two signals. The function is evaluated when a value arrives on either signal. If no value is held by either of the input signals, then the output signal holds no value.

Type Signature
((a, b) -> c, inout (a, b), sig<a>, sig<b>) -> sig<c>
Parameters
f : (a, b) -> c

The mapping function

state : inout (a, b)

Holds the last values received from the signals.

incomingA : sig<a>

The first signal

incomingB : sig<b>

The second signal

Returns

The mapped signal

record

Records values in a list as they come in through the incoming signal.

Type Signature
(inout list<a, n>, sig<a>) -> sig<list<a, n>>
Parameters
pastValues : inout list<a, n>

Previous values recorded from the signal

incoming : sig<a>

Incoming values to record

Returns

A signal holding the list of previous values

constant

Gives a signal holding a specific value.

Type Signature
(a) -> sig<a>
Parameters
val : a

The value that will be held within the signal

Returns

A signal containing the given value

meta

Performs a meta analysis on a signal, and outputs this result in a signal. The output signal will hold a value of nothing when there is no value on the input signal, and will return just the value if there is a value on the input signal.  The output signal will always hold a value, which makes it useful for many applications.

Type Signature
(sig<a>) -> sig<maybe<a>>
Parameters
sigA : sig<a>

The signal on which the meta analysis will be performed

Returns

A signal of either nothing or just the value of the input signal

unmeta

The opposite of the meta function. If the input signal holds a value of nothing, then the output signal will not hold a value. If the input signal holds just a value, then the output signal will hold that value.

Type Signature
(sig<maybe<a>>) -> sig<a>
Parameters
sigA : sig<maybe<a>>

The signal to "make concrete"

Returns

A signal that holds a value in the case of the input signal holding just a value, and holds no value otherwise.

zip

Zips two signals together, so that if a value is received on either signal, then the output signal will also contain the latest value from the other signal. If no value is held by either of the input signals, then the output signal holds no value.

Type Signature
(inout (a, b), sig<a>, sig<b>) -> sig<(a, b)>
Parameters
state : inout (a, b)

The state holding the past values of the signals

sigA : sig<a>

The first signal to zip

sigB : sig<b>

The second signal to zip

Returns

A zipped signal.

unzip

Unzips two signals apart, so that the tuple on the incoming signal is split into two signals.

Type Signature
(sig<(a, b))>) -> (sig<a>, sig<b>)
Parameters
incoming : sig<a>

The signal to unzip

Returns

Two signals inside a tuple

toggle

If a value is carried on the incoming signal, then the output signal holds a value of val2 if the value stored in state is equal to val1; otherwise, the output signal holds a value of val1. If no value is carried on the incoming signal, then no value is outputted on the return signal.

Type Signature
(a, a, inout a, sig<b>) -> sig<a>
Parameters
val1 : a

The first value to toggle between

val2 : a

The second value to toggle between

state : inout a

Holds the previous value outputted on the return signal

incoming : sig<b>

The signal which will trigger a toggle

Returns

A signal containing either val1 or val2, depending on what was previously value carried on the output signal.