bearriver-0.15: FRP Yampa replacement implemented with Monadic Stream Functions.
Copyright(c) Ivan Perez 2019-2022
(c) Ivan Perez and Manuel Baerenz 2016-2018
LicenseBSD3
Maintainerivan.perez@keera.co.uk
Safe HaskellSafe-Inferred
LanguageHaskell2010

FRP.Yampa

Description

 
Synopsis

Documentation

class RandomGen g where #

RandomGen is an interface to pure pseudo-random number generators.

StdGen is the standard RandomGen instance provided by this library.

Since: random-1.0.0

Minimal complete definition

split, (genWord32 | genWord64 | next, genRange)

Methods

next :: g -> (Int, g) #

Returns an Int that is uniformly distributed over the range returned by genRange (including both end points), and a new generator. Using next is inefficient as all operations go via Integer. See here for more details. It is thus deprecated.

Since: random-1.0.0

genWord8 :: g -> (Word8, g) #

Returns a Word8 that is uniformly distributed over the entire Word8 range.

Since: random-1.2.0

genWord16 :: g -> (Word16, g) #

Returns a Word16 that is uniformly distributed over the entire Word16 range.

Since: random-1.2.0

genWord32 :: g -> (Word32, g) #

Returns a Word32 that is uniformly distributed over the entire Word32 range.

Since: random-1.2.0

genWord64 :: g -> (Word64, g) #

Returns a Word64 that is uniformly distributed over the entire Word64 range.

Since: random-1.2.0

genWord32R :: Word32 -> g -> (Word32, g) #

genWord32R upperBound g returns a Word32 that is uniformly distributed over the range [0, upperBound].

Since: random-1.2.0

genWord64R :: Word64 -> g -> (Word64, g) #

genWord64R upperBound g returns a Word64 that is uniformly distributed over the range [0, upperBound].

Since: random-1.2.0

genShortByteString :: Int -> g -> (ShortByteString, g) #

genShortByteString n g returns a ShortByteString of length n filled with pseudo-random bytes.

Since: random-1.2.0

genRange :: g -> (Int, Int) #

Yields the range of values returned by next.

It is required that:

  • If (a, b) = genRange g, then a < b.
  • genRange must not examine its argument so the value it returns is determined only by the instance of RandomGen.

The default definition spans the full range of Int.

Since: random-1.0.0

split :: g -> (g, g) #

Returns two distinct pseudo-random number generators.

Implementations should take care to ensure that the resulting generators are not correlated. Some pseudo-random number generators are not splittable. In that case, the split implementation should fail with a descriptive error message.

Since: random-1.0.0

Instances

Instances details
RandomGen StdGen 
Instance details

Defined in System.Random.Internal

RandomGen SMGen 
Instance details

Defined in System.Random.Internal

RandomGen SMGen 
Instance details

Defined in System.Random.Internal

RandomGen g => RandomGen (StateGen g) 
Instance details

Defined in System.Random.Internal

RandomGen g => RandomGen (AtomicGen g) 
Instance details

Defined in System.Random.Stateful

RandomGen g => RandomGen (IOGen g) 
Instance details

Defined in System.Random.Stateful

Methods

next :: IOGen g -> (Int, IOGen g) #

genWord8 :: IOGen g -> (Word8, IOGen g) #

genWord16 :: IOGen g -> (Word16, IOGen g) #

genWord32 :: IOGen g -> (Word32, IOGen g) #

genWord64 :: IOGen g -> (Word64, IOGen g) #

genWord32R :: Word32 -> IOGen g -> (Word32, IOGen g) #

genWord64R :: Word64 -> IOGen g -> (Word64, IOGen g) #

genShortByteString :: Int -> IOGen g -> (ShortByteString, IOGen g) #

genRange :: IOGen g -> (Int, Int) #

split :: IOGen g -> (IOGen g, IOGen g) #

RandomGen g => RandomGen (STGen g) 
Instance details

Defined in System.Random.Stateful

Methods

next :: STGen g -> (Int, STGen g) #

genWord8 :: STGen g -> (Word8, STGen g) #

genWord16 :: STGen g -> (Word16, STGen g) #

genWord32 :: STGen g -> (Word32, STGen g) #

genWord64 :: STGen g -> (Word64, STGen g) #

genWord32R :: Word32 -> STGen g -> (Word32, STGen g) #

genWord64R :: Word64 -> STGen g -> (Word64, STGen g) #

genShortByteString :: Int -> STGen g -> (ShortByteString, STGen g) #

genRange :: STGen g -> (Int, Int) #

split :: STGen g -> (STGen g, STGen g) #

RandomGen g => RandomGen (TGen g) 
Instance details

Defined in System.Random.Stateful

Methods

next :: TGen g -> (Int, TGen g) #

genWord8 :: TGen g -> (Word8, TGen g) #

genWord16 :: TGen g -> (Word16, TGen g) #

genWord32 :: TGen g -> (Word32, TGen g) #

genWord64 :: TGen g -> (Word64, TGen g) #

genWord32R :: Word32 -> TGen g -> (Word32, TGen g) #

genWord64R :: Word64 -> TGen g -> (Word64, TGen g) #

genShortByteString :: Int -> TGen g -> (ShortByteString, TGen g) #

genRange :: TGen g -> (Int, Int) #

split :: TGen g -> (TGen g, TGen g) #

class Random a where #

The class of types for which random values can be generated. Most instances of Random will produce values that are uniformly distributed on the full range, but for those types without a well-defined "full range" some sensible default subrange will be selected.

Random exists primarily for backwards compatibility with version 1.1 of this library. In new code, use the better specified Uniform and UniformRange instead.

Since: random-1.0.0

Minimal complete definition

Nothing

Methods

randomR :: RandomGen g => (a, a) -> g -> (a, g) #

Takes a range (lo,hi) and a pseudo-random number generator g, and returns a pseudo-random value uniformly distributed over the closed interval [lo,hi], together with a new generator. It is unspecified what happens if lo>hi, but usually the values will simply get swapped.

>>> let gen = mkStdGen 2021
>>> fst $ randomR ('a', 'z') gen
't'
>>> fst $ randomR ('z', 'a') gen
't'

For continuous types there is no requirement that the values lo and hi are ever produced, but they may be, depending on the implementation and the interval.

There is no requirement to follow the Ord instance and the concept of range can be defined on per type basis. For example product types will treat their values independently:

>>> fst $ randomR (('a', 5.0), ('z', 10.0)) $ mkStdGen 2021
('t',6.240232662366563)

In case when a lawful range is desired uniformR should be used instead.

Since: random-1.0.0

random :: RandomGen g => g -> (a, g) #

The same as randomR, but using a default range determined by the type:

  • For bounded types (instances of Bounded, such as Char), the range is normally the whole type.
  • For floating point types, the range is normally the closed interval [0,1].
  • For Integer, the range is (arbitrarily) the range of Int.

Since: random-1.0.0

randomRs :: RandomGen g => (a, a) -> g -> [a] #

Plural variant of randomR, producing an infinite list of pseudo-random values instead of returning a new generator.

Since: random-1.0.0

randoms :: RandomGen g => g -> [a] #

Plural variant of random, producing an infinite list of pseudo-random values instead of returning a new generator.

Since: random-1.0.0

Instances

Instances details
Random CBool 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CBool, CBool) -> g -> (CBool, g) #

random :: RandomGen g => g -> (CBool, g) #

randomRs :: RandomGen g => (CBool, CBool) -> g -> [CBool] #

randoms :: RandomGen g => g -> [CBool] #

Random CChar 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CChar, CChar) -> g -> (CChar, g) #

random :: RandomGen g => g -> (CChar, g) #

randomRs :: RandomGen g => (CChar, CChar) -> g -> [CChar] #

randoms :: RandomGen g => g -> [CChar] #

Random CDouble

Note - random produces values in the closed range [0,1].

Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CDouble, CDouble) -> g -> (CDouble, g) #

random :: RandomGen g => g -> (CDouble, g) #

randomRs :: RandomGen g => (CDouble, CDouble) -> g -> [CDouble] #

randoms :: RandomGen g => g -> [CDouble] #

Random CFloat

Note - random produces values in the closed range [0,1].

Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CFloat, CFloat) -> g -> (CFloat, g) #

random :: RandomGen g => g -> (CFloat, g) #

randomRs :: RandomGen g => (CFloat, CFloat) -> g -> [CFloat] #

randoms :: RandomGen g => g -> [CFloat] #

Random CInt 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CInt, CInt) -> g -> (CInt, g) #

random :: RandomGen g => g -> (CInt, g) #

randomRs :: RandomGen g => (CInt, CInt) -> g -> [CInt] #

randoms :: RandomGen g => g -> [CInt] #

Random CIntMax 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CIntMax, CIntMax) -> g -> (CIntMax, g) #

random :: RandomGen g => g -> (CIntMax, g) #

randomRs :: RandomGen g => (CIntMax, CIntMax) -> g -> [CIntMax] #

randoms :: RandomGen g => g -> [CIntMax] #

Random CIntPtr 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CIntPtr, CIntPtr) -> g -> (CIntPtr, g) #

random :: RandomGen g => g -> (CIntPtr, g) #

randomRs :: RandomGen g => (CIntPtr, CIntPtr) -> g -> [CIntPtr] #

randoms :: RandomGen g => g -> [CIntPtr] #

Random CLLong 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CLLong, CLLong) -> g -> (CLLong, g) #

random :: RandomGen g => g -> (CLLong, g) #

randomRs :: RandomGen g => (CLLong, CLLong) -> g -> [CLLong] #

randoms :: RandomGen g => g -> [CLLong] #

Random CLong 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CLong, CLong) -> g -> (CLong, g) #

random :: RandomGen g => g -> (CLong, g) #

randomRs :: RandomGen g => (CLong, CLong) -> g -> [CLong] #

randoms :: RandomGen g => g -> [CLong] #

Random CPtrdiff 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CPtrdiff, CPtrdiff) -> g -> (CPtrdiff, g) #

random :: RandomGen g => g -> (CPtrdiff, g) #

randomRs :: RandomGen g => (CPtrdiff, CPtrdiff) -> g -> [CPtrdiff] #

randoms :: RandomGen g => g -> [CPtrdiff] #

Random CSChar 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CSChar, CSChar) -> g -> (CSChar, g) #

random :: RandomGen g => g -> (CSChar, g) #

randomRs :: RandomGen g => (CSChar, CSChar) -> g -> [CSChar] #

randoms :: RandomGen g => g -> [CSChar] #

Random CShort 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CShort, CShort) -> g -> (CShort, g) #

random :: RandomGen g => g -> (CShort, g) #

randomRs :: RandomGen g => (CShort, CShort) -> g -> [CShort] #

randoms :: RandomGen g => g -> [CShort] #

Random CSigAtomic 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CSigAtomic, CSigAtomic) -> g -> (CSigAtomic, g) #

random :: RandomGen g => g -> (CSigAtomic, g) #

randomRs :: RandomGen g => (CSigAtomic, CSigAtomic) -> g -> [CSigAtomic] #

randoms :: RandomGen g => g -> [CSigAtomic] #

Random CSize 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CSize, CSize) -> g -> (CSize, g) #

random :: RandomGen g => g -> (CSize, g) #

randomRs :: RandomGen g => (CSize, CSize) -> g -> [CSize] #

randoms :: RandomGen g => g -> [CSize] #

Random CUChar 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CUChar, CUChar) -> g -> (CUChar, g) #

random :: RandomGen g => g -> (CUChar, g) #

randomRs :: RandomGen g => (CUChar, CUChar) -> g -> [CUChar] #

randoms :: RandomGen g => g -> [CUChar] #

Random CUInt 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CUInt, CUInt) -> g -> (CUInt, g) #

random :: RandomGen g => g -> (CUInt, g) #

randomRs :: RandomGen g => (CUInt, CUInt) -> g -> [CUInt] #

randoms :: RandomGen g => g -> [CUInt] #

Random CUIntMax 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CUIntMax, CUIntMax) -> g -> (CUIntMax, g) #

random :: RandomGen g => g -> (CUIntMax, g) #

randomRs :: RandomGen g => (CUIntMax, CUIntMax) -> g -> [CUIntMax] #

randoms :: RandomGen g => g -> [CUIntMax] #

Random CUIntPtr 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CUIntPtr, CUIntPtr) -> g -> (CUIntPtr, g) #

random :: RandomGen g => g -> (CUIntPtr, g) #

randomRs :: RandomGen g => (CUIntPtr, CUIntPtr) -> g -> [CUIntPtr] #

randoms :: RandomGen g => g -> [CUIntPtr] #

Random CULLong 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CULLong, CULLong) -> g -> (CULLong, g) #

random :: RandomGen g => g -> (CULLong, g) #

randomRs :: RandomGen g => (CULLong, CULLong) -> g -> [CULLong] #

randoms :: RandomGen g => g -> [CULLong] #

Random CULong 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CULong, CULong) -> g -> (CULong, g) #

random :: RandomGen g => g -> (CULong, g) #

randomRs :: RandomGen g => (CULong, CULong) -> g -> [CULong] #

randoms :: RandomGen g => g -> [CULong] #

Random CUShort 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CUShort, CUShort) -> g -> (CUShort, g) #

random :: RandomGen g => g -> (CUShort, g) #

randomRs :: RandomGen g => (CUShort, CUShort) -> g -> [CUShort] #

randoms :: RandomGen g => g -> [CUShort] #

Random CWchar 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (CWchar, CWchar) -> g -> (CWchar, g) #

random :: RandomGen g => g -> (CWchar, g) #

randomRs :: RandomGen g => (CWchar, CWchar) -> g -> [CWchar] #

randoms :: RandomGen g => g -> [CWchar] #

Random Int16 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Int16, Int16) -> g -> (Int16, g) #

random :: RandomGen g => g -> (Int16, g) #

randomRs :: RandomGen g => (Int16, Int16) -> g -> [Int16] #

randoms :: RandomGen g => g -> [Int16] #

Random Int32 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Int32, Int32) -> g -> (Int32, g) #

random :: RandomGen g => g -> (Int32, g) #

randomRs :: RandomGen g => (Int32, Int32) -> g -> [Int32] #

randoms :: RandomGen g => g -> [Int32] #

Random Int64 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Int64, Int64) -> g -> (Int64, g) #

random :: RandomGen g => g -> (Int64, g) #

randomRs :: RandomGen g => (Int64, Int64) -> g -> [Int64] #

randoms :: RandomGen g => g -> [Int64] #

Random Int8 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Int8, Int8) -> g -> (Int8, g) #

random :: RandomGen g => g -> (Int8, g) #

randomRs :: RandomGen g => (Int8, Int8) -> g -> [Int8] #

randoms :: RandomGen g => g -> [Int8] #

Random Word16 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Word16, Word16) -> g -> (Word16, g) #

random :: RandomGen g => g -> (Word16, g) #

randomRs :: RandomGen g => (Word16, Word16) -> g -> [Word16] #

randoms :: RandomGen g => g -> [Word16] #

Random Word32 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Word32, Word32) -> g -> (Word32, g) #

random :: RandomGen g => g -> (Word32, g) #

randomRs :: RandomGen g => (Word32, Word32) -> g -> [Word32] #

randoms :: RandomGen g => g -> [Word32] #

Random Word64 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Word64, Word64) -> g -> (Word64, g) #

random :: RandomGen g => g -> (Word64, g) #

randomRs :: RandomGen g => (Word64, Word64) -> g -> [Word64] #

randoms :: RandomGen g => g -> [Word64] #

Random Word8 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Word8, Word8) -> g -> (Word8, g) #

random :: RandomGen g => g -> (Word8, g) #

randomRs :: RandomGen g => (Word8, Word8) -> g -> [Word8] #

randoms :: RandomGen g => g -> [Word8] #

Random Integer

Note - random generates values in the Int range

Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Integer, Integer) -> g -> (Integer, g) #

random :: RandomGen g => g -> (Integer, g) #

randomRs :: RandomGen g => (Integer, Integer) -> g -> [Integer] #

randoms :: RandomGen g => g -> [Integer] #

Random Bool 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Bool, Bool) -> g -> (Bool, g) #

random :: RandomGen g => g -> (Bool, g) #

randomRs :: RandomGen g => (Bool, Bool) -> g -> [Bool] #

randoms :: RandomGen g => g -> [Bool] #

Random Char 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Char, Char) -> g -> (Char, g) #

random :: RandomGen g => g -> (Char, g) #

randomRs :: RandomGen g => (Char, Char) -> g -> [Char] #

randoms :: RandomGen g => g -> [Char] #

Random Double

Note - random produces values in the closed range [0,1].

Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Double, Double) -> g -> (Double, g) #

random :: RandomGen g => g -> (Double, g) #

randomRs :: RandomGen g => (Double, Double) -> g -> [Double] #

randoms :: RandomGen g => g -> [Double] #

Random Float

Note - random produces values in the closed range [0,1].

Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Float, Float) -> g -> (Float, g) #

random :: RandomGen g => g -> (Float, g) #

randomRs :: RandomGen g => (Float, Float) -> g -> [Float] #

randoms :: RandomGen g => g -> [Float] #

Random Int 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Int, Int) -> g -> (Int, g) #

random :: RandomGen g => g -> (Int, g) #

randomRs :: RandomGen g => (Int, Int) -> g -> [Int] #

randoms :: RandomGen g => g -> [Int] #

Random Word 
Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => (Word, Word) -> g -> (Word, g) #

random :: RandomGen g => g -> (Word, g) #

randomRs :: RandomGen g => (Word, Word) -> g -> [Word] #

randoms :: RandomGen g => g -> [Word] #

(Random a, Random b) => Random (a, b)

Note - randomR treats a and b types independently

Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => ((a, b), (a, b)) -> g -> ((a, b), g) #

random :: RandomGen g => g -> ((a, b), g) #

randomRs :: RandomGen g => ((a, b), (a, b)) -> g -> [(a, b)] #

randoms :: RandomGen g => g -> [(a, b)] #

(Random a, Random b, Random c) => Random (a, b, c)

Note - randomR treats a, b and c types independently

Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => ((a, b, c), (a, b, c)) -> g -> ((a, b, c), g) #

random :: RandomGen g => g -> ((a, b, c), g) #

randomRs :: RandomGen g => ((a, b, c), (a, b, c)) -> g -> [(a, b, c)] #

randoms :: RandomGen g => g -> [(a, b, c)] #

(Random a, Random b, Random c, Random d) => Random (a, b, c, d)

Note - randomR treats a, b, c and d types independently

Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => ((a, b, c, d), (a, b, c, d)) -> g -> ((a, b, c, d), g) #

random :: RandomGen g => g -> ((a, b, c, d), g) #

randomRs :: RandomGen g => ((a, b, c, d), (a, b, c, d)) -> g -> [(a, b, c, d)] #

randoms :: RandomGen g => g -> [(a, b, c, d)] #

(Random a, Random b, Random c, Random d, Random e) => Random (a, b, c, d, e)

Note - randomR treats a, b, c, d and e types independently

Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => ((a, b, c, d, e), (a, b, c, d, e)) -> g -> ((a, b, c, d, e), g) #

random :: RandomGen g => g -> ((a, b, c, d, e), g) #

randomRs :: RandomGen g => ((a, b, c, d, e), (a, b, c, d, e)) -> g -> [(a, b, c, d, e)] #

randoms :: RandomGen g => g -> [(a, b, c, d, e)] #

(Random a, Random b, Random c, Random d, Random e, Random f) => Random (a, b, c, d, e, f)

Note - randomR treats a, b, c, d, e and f types independently

Instance details

Defined in System.Random

Methods

randomR :: RandomGen g => ((a, b, c, d, e, f), (a, b, c, d, e, f)) -> g -> ((a, b, c, d, e, f), g) #

random :: RandomGen g => g -> ((a, b, c, d, e, f), g) #

randomRs :: RandomGen g => ((a, b, c, d, e, f), (a, b, c, d, e, f)) -> g -> [(a, b, c, d, e, f)] #

randoms :: RandomGen g => g -> [(a, b, c, d, e, f)] #

(Random a, Random b, Random c, Random d, Random e, Random f, Random g) => Random (a, b, c, d, e, f, g)

Note - randomR treats a, b, c, d, e, f and g types independently

Instance details

Defined in System.Random

Methods

randomR :: RandomGen g0 => ((a, b, c, d, e, f, g), (a, b, c, d, e, f, g)) -> g0 -> ((a, b, c, d, e, f, g), g0) #

random :: RandomGen g0 => g0 -> ((a, b, c, d, e, f, g), g0) #

randomRs :: RandomGen g0 => ((a, b, c, d, e, f, g), (a, b, c, d, e, f, g)) -> g0 -> [(a, b, c, d, e, f, g)] #

randoms :: RandomGen g0 => g0 -> [(a, b, c, d, e, f, g)] #

data Event a Source #

A single possible event occurrence, that is, a value that may or may not occur. Events are used to represent values that are not produced continuously, such as mouse clicks (only produced when the mouse is clicked, as opposed to mouse positions, which are always defined).

Constructors

Event a 
NoEvent 

Instances

Instances details
MonadFail Event Source #

MonadFail instance

Instance details

Defined in FRP.BearRiver.Event

Methods

fail :: String -> Event a #

Alternative Event Source #

Alternative instance.

Instance details

Defined in FRP.BearRiver.Event

Methods

empty :: Event a #

(<|>) :: Event a -> Event a -> Event a #

some :: Event a -> Event [a] #

many :: Event a -> Event [a] #

Applicative Event Source #

Applicative instance (similar to Maybe).

Instance details

Defined in FRP.BearRiver.Event

Methods

pure :: a -> Event a #

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

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

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

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

Functor Event Source #

Functor instance (could be derived).

Instance details

Defined in FRP.BearRiver.Event

Methods

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

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

Monad Event Source #

Monad instance.

Instance details

Defined in FRP.BearRiver.Event

Methods

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

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

return :: a -> Event a #

Show a => Show (Event a) Source # 
Instance details

Defined in FRP.BearRiver.Event

Methods

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

show :: Event a -> String #

showList :: [Event a] -> ShowS #

NFData a => NFData (Event a) Source #

NFData instance.

Instance details

Defined in FRP.BearRiver.Event

Methods

rnf :: Event a -> () #

Eq a => Eq (Event a) Source # 
Instance details

Defined in FRP.BearRiver.Event

Methods

(==) :: Event a -> Event a -> Bool #

(/=) :: Event a -> Event a -> Bool #

Ord a => Ord (Event a) Source # 
Instance details

Defined in FRP.BearRiver.Event

Methods

compare :: Event a -> Event a -> Ordering #

(<) :: Event a -> Event a -> Bool #

(<=) :: Event a -> Event a -> Bool #

(>) :: Event a -> Event a -> Bool #

(>=) :: Event a -> Event a -> Bool #

max :: Event a -> Event a -> Event a #

min :: Event a -> Event a -> Event a #

class Arrow a => ArrowLoop (a :: Type -> Type -> Type) where #

The loop operator expresses computations in which an output value is fed back as input, although the computation occurs only once. It underlies the rec value recursion construct in arrow notation. loop should satisfy the following laws:

extension
loop (arr f) = arr (\ b -> fst (fix (\ (c,d) -> f (b,d))))
left tightening
loop (first h >>> f) = h >>> loop f
right tightening
loop (f >>> first h) = loop f >>> h
sliding
loop (f >>> arr (id *** k)) = loop (arr (id *** k) >>> f)
vanishing
loop (loop f) = loop (arr unassoc >>> f >>> arr assoc)
superposing
second (loop f) = loop (arr assoc >>> second f >>> arr unassoc)

where

assoc ((a,b),c) = (a,(b,c))
unassoc (a,(b,c)) = ((a,b),c)

Methods

loop :: a (b, d) (c, d) -> a b c #

Instances

Instances details
MonadFix m => ArrowLoop (Kleisli m)

Beware that for many monads (those for which the >>= operation is strict) this instance will not satisfy the right-tightening law required by the ArrowLoop class.

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

loop :: Kleisli m (b, d) (c, d) -> Kleisli m b c #

ArrowLoop (->)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

loop :: ((b, d) -> (c, d)) -> b -> c #

newtype ArrowMonad (a :: Type -> Type -> Type) b #

The ArrowApply class is equivalent to Monad: any monad gives rise to a Kleisli arrow, and any instance of ArrowApply defines a monad.

Constructors

ArrowMonad (a () b) 

Instances

Instances details
ArrowPlus a => Alternative (ArrowMonad a)

Since: base-4.6.0.0

Instance details

Defined in Control.Arrow

Methods

empty :: ArrowMonad a a0 #

(<|>) :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 #

some :: ArrowMonad a a0 -> ArrowMonad a [a0] #

many :: ArrowMonad a a0 -> ArrowMonad a [a0] #

Arrow a => Applicative (ArrowMonad a)

Since: base-4.6.0.0

Instance details

Defined in Control.Arrow

Methods

pure :: a0 -> ArrowMonad a a0 #

(<*>) :: ArrowMonad a (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b #

liftA2 :: (a0 -> b -> c) -> ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a c #

(*>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b #

(<*) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a a0 #

Arrow a => Functor (ArrowMonad a)

Since: base-4.6.0.0

Instance details

Defined in Control.Arrow

Methods

fmap :: (a0 -> b) -> ArrowMonad a a0 -> ArrowMonad a b #

(<$) :: a0 -> ArrowMonad a b -> ArrowMonad a a0 #

ArrowApply a => Monad (ArrowMonad a)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

(>>=) :: ArrowMonad a a0 -> (a0 -> ArrowMonad a b) -> ArrowMonad a b #

(>>) :: ArrowMonad a a0 -> ArrowMonad a b -> ArrowMonad a b #

return :: a0 -> ArrowMonad a a0 #

(ArrowApply a, ArrowPlus a) => MonadPlus (ArrowMonad a)

Since: base-4.6.0.0

Instance details

Defined in Control.Arrow

Methods

mzero :: ArrowMonad a a0 #

mplus :: ArrowMonad a a0 -> ArrowMonad a a0 -> ArrowMonad a a0 #

class Arrow a => ArrowApply (a :: Type -> Type -> Type) where #

Some arrows allow application of arrow inputs to other inputs. Instances should satisfy the following laws:

Such arrows are equivalent to monads (see ArrowMonad).

Methods

app :: a (a b c, b) c #

Instances

Instances details
Monad m => ArrowApply (Kleisli m)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

app :: Kleisli m (Kleisli m b c, b) c #

ArrowApply (->)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

app :: (b -> c, b) -> c #

class Arrow a => ArrowChoice (a :: Type -> Type -> Type) where #

Choice, for arrows that support it. This class underlies the if and case constructs in arrow notation.

Instances should satisfy the following laws:

where

assocsum (Left (Left x)) = Left x
assocsum (Left (Right y)) = Right (Left y)
assocsum (Right z) = Right (Right z)

The other combinators have sensible default definitions, which may be overridden for efficiency.

Minimal complete definition

(left | (+++))

Methods

left :: a b c -> a (Either b d) (Either c d) #

Feed marked inputs through the argument arrow, passing the rest through unchanged to the output.

right :: a b c -> a (Either d b) (Either d c) #

A mirror image of left.

The default definition may be overridden with a more efficient version if desired.

(+++) :: a b c -> a b' c' -> a (Either b b') (Either c c') infixr 2 #

Split the input between the two argument arrows, retagging and merging their outputs. Note that this is in general not a functor.

The default definition may be overridden with a more efficient version if desired.

(|||) :: a b d -> a c d -> a (Either b c) d infixr 2 #

Fanin: Split the input between the two argument arrows and merge their outputs.

The default definition may be overridden with a more efficient version if desired.

Instances

Instances details
Monad m => ArrowChoice (Kleisli m)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

left :: Kleisli m b c -> Kleisli m (Either b d) (Either c d) #

right :: Kleisli m b c -> Kleisli m (Either d b) (Either d c) #

(+++) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (Either b b') (Either c c') #

(|||) :: Kleisli m b d -> Kleisli m c d -> Kleisli m (Either b c) d #

ArrowChoice (->)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

left :: (b -> c) -> Either b d -> Either c d #

right :: (b -> c) -> Either d b -> Either d c #

(+++) :: (b -> c) -> (b' -> c') -> Either b b' -> Either c c' #

(|||) :: (b -> d) -> (c -> d) -> Either b c -> d #

class ArrowZero a => ArrowPlus (a :: Type -> Type -> Type) where #

A monoid on arrows.

Methods

(<+>) :: a b c -> a b c -> a b c infixr 5 #

An associative operation with identity zeroArrow.

Instances

Instances details
MonadPlus m => ArrowPlus (Kleisli m)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

(<+>) :: Kleisli m b c -> Kleisli m b c -> Kleisli m b c #

class Arrow a => ArrowZero (a :: Type -> Type -> Type) where #

Methods

zeroArrow :: a b c #

Instances

Instances details
MonadPlus m => ArrowZero (Kleisli m)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

zeroArrow :: Kleisli m b c #

newtype Kleisli (m :: Type -> Type) a b #

Kleisli arrows of a monad.

Constructors

Kleisli 

Fields

Instances

Instances details
Monad m => Category (Kleisli m :: Type -> Type -> Type)

Since: base-3.0

Instance details

Defined in Control.Arrow

Methods

id :: forall (a :: k). Kleisli m a a #

(.) :: forall (b :: k) (c :: k) (a :: k). Kleisli m b c -> Kleisli m a b -> Kleisli m a c #

Generic1 (Kleisli m a :: Type -> Type) 
Instance details

Defined in Control.Arrow

Associated Types

type Rep1 (Kleisli m a) :: k -> Type #

Methods

from1 :: forall (a0 :: k). Kleisli m a a0 -> Rep1 (Kleisli m a) a0 #

to1 :: forall (a0 :: k). Rep1 (Kleisli m a) a0 -> Kleisli m a a0 #

Monad m => Arrow (Kleisli m)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

arr :: (b -> c) -> Kleisli m b c #

first :: Kleisli m b c -> Kleisli m (b, d) (c, d) #

second :: Kleisli m b c -> Kleisli m (d, b) (d, c) #

(***) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (b, b') (c, c') #

(&&&) :: Kleisli m b c -> Kleisli m b c' -> Kleisli m b (c, c') #

Monad m => ArrowApply (Kleisli m)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

app :: Kleisli m (Kleisli m b c, b) c #

Monad m => ArrowChoice (Kleisli m)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

left :: Kleisli m b c -> Kleisli m (Either b d) (Either c d) #

right :: Kleisli m b c -> Kleisli m (Either d b) (Either d c) #

(+++) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (Either b b') (Either c c') #

(|||) :: Kleisli m b d -> Kleisli m c d -> Kleisli m (Either b c) d #

MonadFix m => ArrowLoop (Kleisli m)

Beware that for many monads (those for which the >>= operation is strict) this instance will not satisfy the right-tightening law required by the ArrowLoop class.

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

loop :: Kleisli m (b, d) (c, d) -> Kleisli m b c #

MonadPlus m => ArrowPlus (Kleisli m)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

(<+>) :: Kleisli m b c -> Kleisli m b c -> Kleisli m b c #

MonadPlus m => ArrowZero (Kleisli m)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

zeroArrow :: Kleisli m b c #

Alternative m => Alternative (Kleisli m a)

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

Methods

empty :: Kleisli m a a0 #

(<|>) :: Kleisli m a a0 -> Kleisli m a a0 -> Kleisli m a a0 #

some :: Kleisli m a a0 -> Kleisli m a [a0] #

many :: Kleisli m a a0 -> Kleisli m a [a0] #

Applicative m => Applicative (Kleisli m a)

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

Methods

pure :: a0 -> Kleisli m a a0 #

(<*>) :: Kleisli m a (a0 -> b) -> Kleisli m a a0 -> Kleisli m a b #

liftA2 :: (a0 -> b -> c) -> Kleisli m a a0 -> Kleisli m a b -> Kleisli m a c #

(*>) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a b #

(<*) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a a0 #

Functor m => Functor (Kleisli m a)

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

Methods

fmap :: (a0 -> b) -> Kleisli m a a0 -> Kleisli m a b #

(<$) :: a0 -> Kleisli m a b -> Kleisli m a a0 #

Monad m => Monad (Kleisli m a)

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

Methods

(>>=) :: Kleisli m a a0 -> (a0 -> Kleisli m a b) -> Kleisli m a b #

(>>) :: Kleisli m a a0 -> Kleisli m a b -> Kleisli m a b #

return :: a0 -> Kleisli m a a0 #

MonadPlus m => MonadPlus (Kleisli m a)

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

Methods

mzero :: Kleisli m a a0 #

mplus :: Kleisli m a a0 -> Kleisli m a a0 -> Kleisli m a a0 #

Generic (Kleisli m a b) 
Instance details

Defined in Control.Arrow

Associated Types

type Rep (Kleisli m a b) :: Type -> Type #

Methods

from :: Kleisli m a b -> Rep (Kleisli m a b) x #

to :: Rep (Kleisli m a b) x -> Kleisli m a b #

type Rep1 (Kleisli m a :: Type -> Type)

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

type Rep1 (Kleisli m a :: Type -> Type) = D1 ('MetaData "Kleisli" "Control.Arrow" "base" 'True) (C1 ('MetaCons "Kleisli" 'PrefixI 'True) (S1 ('MetaSel ('Just "runKleisli") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) ((FUN 'Many a :: Type -> Type) :.: Rec1 m)))
type Rep (Kleisli m a b)

Since: base-4.14.0.0

Instance details

Defined in Control.Arrow

type Rep (Kleisli m a b) = D1 ('MetaData "Kleisli" "Control.Arrow" "base" 'True) (C1 ('MetaCons "Kleisli" 'PrefixI 'True) (S1 ('MetaSel ('Just "runKleisli") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (a -> m b))))

class Category a => Arrow (a :: Type -> Type -> Type) where #

The basic arrow class.

Instances should satisfy the following laws:

where

assoc ((a,b),c) = (a,(b,c))

The other combinators have sensible default definitions, which may be overridden for efficiency.

Minimal complete definition

arr, (first | (***))

Methods

arr :: (b -> c) -> a b c #

Lift a function to an arrow.

first :: a b c -> a (b, d) (c, d) #

Send the first component of the input through the argument arrow, and copy the rest unchanged to the output.

second :: a b c -> a (d, b) (d, c) #

A mirror image of first.

The default definition may be overridden with a more efficient version if desired.

(***) :: a b c -> a b' c' -> a (b, b') (c, c') infixr 3 #

Split the input between the two argument arrows and combine their output. Note that this is in general not a functor.

The default definition may be overridden with a more efficient version if desired.

(&&&) :: a b c -> a b c' -> a b (c, c') infixr 3 #

Fanout: send the input to both argument arrows and combine their output.

The default definition may be overridden with a more efficient version if desired.

Instances

Instances details
Monad m => Arrow (Kleisli m)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

arr :: (b -> c) -> Kleisli m b c #

first :: Kleisli m b c -> Kleisli m (b, d) (c, d) #

second :: Kleisli m b c -> Kleisli m (d, b) (d, c) #

(***) :: Kleisli m b c -> Kleisli m b' c' -> Kleisli m (b, b') (c, c') #

(&&&) :: Kleisli m b c -> Kleisli m b c' -> Kleisli m b (c, c') #

Arrow (->)

Since: base-2.1

Instance details

Defined in Control.Arrow

Methods

arr :: (b -> c) -> b -> c #

first :: (b -> c) -> (b, d) -> (c, d) #

second :: (b -> c) -> (d, b) -> (d, c) #

(***) :: (b -> c) -> (b' -> c') -> (b, b') -> (c, c') #

(&&&) :: (b -> c) -> (b -> c') -> b -> (c, c') #

data MSF (m :: Type -> Type) a b #

Stepwise, side-effectful MSFs without implicit knowledge of time.

MSFs should be applied to streams or executed indefinitely or until they terminate. See reactimate and reactimateB for details. In general, calling the value constructor MSF or the function unMSF is discouraged.

Instances

Instances details
Monad m => Category (MSF m :: Type -> Type -> Type)

Instance definition for Category. Defines id and ..

Instance details

Defined in Data.MonadicStreamFunction.InternalCore

Methods

id :: forall (a :: k). MSF m a a #

(.) :: forall (b :: k) (c :: k) (a :: k). MSF m b c -> MSF m a b -> MSF m a c #

type MSink (m :: Type -> Type) a = MSF m a () #

A sink is an MSF that consumes inputs, while producing no output. It can consume the values with side effects.

type MStream (m :: Type -> Type) a = MSF m () a #

A stream is an MSF that produces outputs, while ignoring the input. It can obtain the values from a monadic context.

data ReactHandle a b Source #

A reference to reactimate's state, maintained across samples.

class VectorSpace v a | v -> a where #

Vector space type relation.

A vector space is a set (type) closed under addition and multiplication by a scalar. The type of the scalar is the field of the vector space, and it is said that v is a vector space over a.

The encoding uses a type class |VectorSpace| v a, where v represents the type of the vectors and a represents the types of the scalars.

Minimal complete definition

zeroVector, (*^), (^+^), dot

Methods

zeroVector :: v #

Vector with no magnitude (unit for addition).

(*^) :: a -> v -> v infixr 9 #

Multiplication by a scalar.

(^/) :: v -> a -> v infixl 9 #

Division by a scalar.

(^+^) :: v -> v -> v infixl 6 #

Vector addition

(^-^) :: v -> v -> v infixl 6 #

Vector subtraction

negateVector :: v -> v #

Vector negation. Addition with a negated vector should be same as subtraction.

dot :: v -> v -> a infix 7 #

Dot product (also known as scalar or inner product).

For two vectors, mathematically represented as a = a1,a2,...,an and b = b1,b2,...,bn, the dot product is a . b = a1*b1 + a2*b2 + ... + an*bn.

Some properties are derived from this. The dot product of a vector with itself is the square of its magnitude (norm), and the dot product of two orthogonal vectors is zero.

norm :: v -> a #

Vector's norm (also known as magnitude).

For a vector represented mathematically as a = a1,a2,...,an, the norm is the square root of a1^2 + a2^2 + ... + an^2.

normalize :: v -> v #

Return a vector with the same origin and orientation (angle), but such that the norm is one (the unit for multiplication by a scalar).

Instances

Instances details
VectorSpace Double Double

Vector space instance for Doubles, with Double scalars.

Instance details

Defined in Data.VectorSpace

VectorSpace Float Float

Vector space instance for Floats, with Float scalars.

Instance details

Defined in Data.VectorSpace

(Eq a, Floating a) => VectorSpace (a, a) a

Vector space instance for pairs of Floating point numbers.

Instance details

Defined in Data.VectorSpace

Methods

zeroVector :: (a, a) #

(*^) :: a -> (a, a) -> (a, a) #

(^/) :: (a, a) -> a -> (a, a) #

(^+^) :: (a, a) -> (a, a) -> (a, a) #

(^-^) :: (a, a) -> (a, a) -> (a, a) #

negateVector :: (a, a) -> (a, a) #

dot :: (a, a) -> (a, a) -> a #

norm :: (a, a) -> a #

normalize :: (a, a) -> (a, a) #

(Eq a, Floating a) => VectorSpace (a, a, a) a

Vector space instance for triplets of Floating point numbers.

Instance details

Defined in Data.VectorSpace

Methods

zeroVector :: (a, a, a) #

(*^) :: a -> (a, a, a) -> (a, a, a) #

(^/) :: (a, a, a) -> a -> (a, a, a) #

(^+^) :: (a, a, a) -> (a, a, a) -> (a, a, a) #

(^-^) :: (a, a, a) -> (a, a, a) -> (a, a, a) #

negateVector :: (a, a, a) -> (a, a, a) #

dot :: (a, a, a) -> (a, a, a) -> a #

norm :: (a, a, a) -> a #

normalize :: (a, a, a) -> (a, a, a) #

(Eq a, Floating a) => VectorSpace (a, a, a, a) a

Vector space instance for tuples with four Floating point numbers.

Instance details

Defined in Data.VectorSpace

Methods

zeroVector :: (a, a, a, a) #

(*^) :: a -> (a, a, a, a) -> (a, a, a, a) #

(^/) :: (a, a, a, a) -> a -> (a, a, a, a) #

(^+^) :: (a, a, a, a) -> (a, a, a, a) -> (a, a, a, a) #

(^-^) :: (a, a, a, a) -> (a, a, a, a) -> (a, a, a, a) #

negateVector :: (a, a, a, a) -> (a, a, a, a) #

dot :: (a, a, a, a) -> (a, a, a, a) -> a #

norm :: (a, a, a, a) -> a #

normalize :: (a, a, a, a) -> (a, a, a, a) #

(Eq a, Floating a) => VectorSpace (a, a, a, a, a) a

Vector space instance for tuples with five Floating point numbers.

Instance details

Defined in Data.VectorSpace

Methods

zeroVector :: (a, a, a, a, a) #

(*^) :: a -> (a, a, a, a, a) -> (a, a, a, a, a) #

(^/) :: (a, a, a, a, a) -> a -> (a, a, a, a, a) #

(^+^) :: (a, a, a, a, a) -> (a, a, a, a, a) -> (a, a, a, a, a) #

(^-^) :: (a, a, a, a, a) -> (a, a, a, a, a) -> (a, a, a, a, a) #

negateVector :: (a, a, a, a, a) -> (a, a, a, a, a) #

dot :: (a, a, a, a, a) -> (a, a, a, a, a) -> a #

norm :: (a, a, a, a, a) -> a #

normalize :: (a, a, a, a, a) -> (a, a, a, a, a) #

data Task m a b c Source #

A task is a partially SF that may terminate with a result.

Instances

Instances details
Monad m => Applicative (Task m a b) Source # 
Instance details

Defined in FRP.BearRiver.Task

Methods

pure :: a0 -> Task m a b a0 #

(<*>) :: Task m a b (a0 -> b0) -> Task m a b a0 -> Task m a b b0 #

liftA2 :: (a0 -> b0 -> c) -> Task m a b a0 -> Task m a b b0 -> Task m a b c #

(*>) :: Task m a b a0 -> Task m a b b0 -> Task m a b b0 #

(<*) :: Task m a b a0 -> Task m a b b0 -> Task m a b a0 #

Monad m => Functor (Task m a b) Source # 
Instance details

Defined in FRP.BearRiver.Task

Methods

fmap :: (a0 -> b0) -> Task m a b a0 -> Task m a b b0 #

(<$) :: a0 -> Task m a b b0 -> Task m a b a0 #

Monad m => Monad (Task m a b) Source # 
Instance details

Defined in FRP.BearRiver.Task

Methods

(>>=) :: Task m a b a0 -> (a0 -> Task m a b b0) -> Task m a b b0 #

(>>) :: Task m a b a0 -> Task m a b b0 -> Task m a b b0 #

return :: a0 -> Task m a b a0 #

type Time = Double Source #

Time is used both for time intervals (duration), and time w.r.t. some agreed reference point in time.

type DTime = Double Source #

DTime is the time type for lengths of sample intervals. Conceptually, DTime = R+ = { x in R | x > 0 }. Don't assume Time and DTime have the same representation.

type ClockInfo m = ReaderT DTime m Source #

Information on the progress of time.

time :: Monad m => SF m a Time Source #

Alternative name for localTime.

(-=>) :: Monad m => (b -> b) -> SF m a b -> SF m a b infixr 0 Source #

Transform initial output value.

Applies a transformation f only to the first output value at time zero.

accum :: Monad m => a -> SF m (Event (a -> a)) (Event a) Source #

Given an initial value in an accumulator, it returns a signal function that processes an event carrying transformation functions. Every time an Event is received, the function inside it is applied to the accumulator, whose new value is outputted in an Event.

(>>>) :: forall {k} cat (a :: k) (b :: k) (c :: k). Category cat => cat a b -> cat b c -> cat a c infixr 1 #

Left-to-right composition

count :: (Integral b, Monad m) => SF m (Event a) (Event b) Source #

Count the occurrences of input events.

>>> embed count (deltaEncode 1 [Event 'a', NoEvent, Event 'b'])
[Event 1,NoEvent,Event 2]

(<<<) :: forall {k} cat (b :: k) (c :: k) (a :: k). Category cat => cat b c -> cat a b -> cat a c infixr 1 #

Right-to-left composition

dup :: a -> (a, a) Source #

Duplicate an input.

par Source #

Arguments

:: (Functor m, Monad m, Functor col, Traversable col) 
=> (forall sf. a -> col sf -> col (b, sf))

Determines the input to each signal function in the collection. IMPORTANT! The routing function MUST preserve the structure of the signal function collection.

-> col (SF m b c)

Signal function collection.

-> SF m a (col c) 

Spatial parallel composition of a signal function collection parameterized on the routing function.

returnA :: Arrow a => a b b #

The identity arrow, which plays the role of return in arrow notation.

(^>>) :: Arrow a => (b -> c) -> a c d -> a b d infixr 1 #

Precomposition with a pure function.

(>>^) :: Arrow a => a b c -> (c -> d) -> a b d infixr 1 #

Postcomposition with a pure function.

(<<^) :: Arrow a => a c d -> (b -> c) -> a b d infixr 1 #

Precomposition with a pure function (right-to-left variant).

(^<<) :: Arrow a => (c -> d) -> a b c -> a b d infixr 1 #

Postcomposition with a pure function (right-to-left variant).

leftApp :: ArrowApply a => a b c -> a (Either b d) (Either c d) #

Any instance of ArrowApply can be made into an instance of ArrowChoice by defining left = leftApp.

traceWith :: (Monad m, Show a) => (String -> m ()) -> String -> MSF m a a #

Outputs every input sample, with a given message prefix, using an auxiliary printing function.

unfold :: forall (m :: Type -> Type) a b. Monad m => (a -> (b, a)) -> a -> MSF m () b #

Generate outputs using a step-wise generation function and an initial value.

merge :: Event a -> Event a -> Event a infixl 6 Source #

Unbiased event merge: simultaneous occurrence is an error.

morphGS #

Arguments

:: Monad m2 
=> (forall c. (a1 -> m1 (b1, c)) -> a2 -> m2 (b2, c))

The natural transformation. mi, ai and bi for i = 1, 2 can be chosen freely, but c must be universally quantified

-> MSF m1 a1 b1 
-> MSF m2 a2 b2 

Generic lifting of a morphism to the level of MSFs.

Natural transformation to the level of MSFs.

Mathematical background: The type a -> m (b, c) is a functor in c, and MSF m a b is its greatest fixpoint, i.e. it is isomorphic to the type a -> m (b, MSF m a b), by definition. The types m, a and b are parameters of the functor. Taking a fixpoint is functorial itself, meaning that a morphism (a natural transformation) of two such functors gives a morphism (an ordinary function) of their fixpoints.

This is in a sense the most general "abstract" lifting function, i.e. the most general one that only changes input, output and side effect types, and doesn't influence control flow. Other handling functions like exception handling or ListT broadcasting necessarily change control flow.

feedback :: forall (m :: Type -> Type) c a b. Monad m => c -> MSF m (a, c) (b, c) -> MSF m a b #

Well-formed looped connection of an output component as a future input.

constM :: Monad m => m b -> MSF m a b #

Lifts a monadic computation into a Stream.

arrM :: Monad m => (a -> m b) -> MSF m a b #

Apply a monadic transformation to every element of the input stream.

Generalisation of arr from Arrow to monadic functions.

liftBaseM :: forall (m2 :: Type -> Type) m1 a b. (Monad m2, MonadBase m1 m2) => (a -> m1 b) -> MSF m2 a b #

Monadic lifting from one monad into another

liftBaseS :: forall (m2 :: Type -> Type) (m1 :: Type -> Type) a b. (Monad m2, MonadBase m1 m2) => MSF m1 a b -> MSF m2 a b #

Lift innermost monadic actions in monad stack (generalisation of liftIO).

(^>>>) :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) a b c. MonadBase m1 m2 => MSF m1 a b -> MSF m2 b c -> MSF m2 a c #

Lift the first MSF into the monad of the second.

(>>>^) :: forall (m1 :: Type -> Type) (m2 :: Type -> Type) a b c. MonadBase m1 m2 => MSF m2 a b -> MSF m1 b c -> MSF m2 a c #

Lift the second MSF into the monad of the first.

liftTransS :: forall (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a b. (MonadTrans t, Monad m, Monad (t m)) => MSF m a b -> MSF (t m) a b #

Lift inner monadic actions in monad stacks.

morphS :: (Monad m2, Monad m1) => (forall c. m1 c -> m2 c) -> MSF m1 a b -> MSF m2 a b #

Apply trans-monadic actions (in an arbitrary way).

This is just a convenience function when you have a function to move across monads, because the signature of morphGS is a bit complex.

mapMaybeS :: forall (m :: Type -> Type) a b. Monad m => MSF m a b -> MSF m (Maybe a) (Maybe b) #

Apply an MSF to every input. Freezes temporarily if the input is Nothing, and continues as soon as a Just is received.

withSideEffect :: Monad m => (a -> m b) -> MSF m a a #

Applies a function to produce an additional side effect and passes the input unchanged.

withSideEffect_ :: Monad m => m b -> MSF m a a #

Produces an additional side effect and passes the input unchanged.

iPre :: Monad m => a -> SF m a a Source #

Initialized delay operator.

Creates an SF that delays the input signal, introducing an infinitesimal delay (one sample), using the given argument to fill in the initial output at time zero.

iPost :: forall (m :: Type -> Type) b a. Monad m => b -> MSF m a b -> MSF m a b #

Preprends a fixed output to an MSF. The first input is completely ignored.

fifo :: forall (m :: Type -> Type) a. Monad m => MSF m [a] (Maybe a) #

Buffers and returns the elements in FIFO order, returning Nothing whenever the buffer is empty.

sumS :: forall v s (m :: Type -> Type). (VectorSpace v s, Monad m) => MSF m v v #

Sums the inputs, starting from zero.

sumFrom :: forall v s (m :: Type -> Type). (VectorSpace v s, Monad m) => v -> MSF m v v #

Sums the inputs, starting from an initial vector.

mappendS :: forall n (m :: Type -> Type). (Monoid n, Monad m) => MSF m n n #

Accumulate the inputs, starting from mempty.

mappendFrom :: forall n (m :: Type -> Type). (Monoid n, Monad m) => n -> MSF m n n #

Accumulate the inputs, starting from an initial monoid value.

accumulateWith :: forall (m :: Type -> Type) a s. Monad m => (a -> s -> s) -> s -> MSF m a s #

Applies a function to the input and an accumulator, outputting the updated accumulator. Equal to f s0 -> feedback s0 $ arr (uncurry f >>> dup).

mealy :: forall (m :: Type -> Type) a s b. Monad m => (a -> s -> (b, s)) -> s -> MSF m a b #

Applies a transfer function to the input and an accumulator, returning the updated accumulator and output.

repeatedly :: Monad m => Time -> b -> SF m a (Event b) Source #

Event source with repeated occurrences with interval q.

Note: If the interval is too short w.r.t. the sampling intervals, the result will be that events occur at every sample. However, no more than one event results from any sampling interval, thus avoiding an "event backlog" should sampling become more frequent at some later point in time.

traceWhen :: (Monad m, Show a) => (a -> Bool) -> (String -> m ()) -> String -> MSF m a a #

Outputs every input sample, with a given message prefix, using an auxiliary printing function, when a condition is met.

pauseOn :: Show a => (a -> Bool) -> String -> MSF IO a a #

Outputs every input sample, with a given message prefix, when a condition is met, and waits for some input / enter to continue.

reactInit :: IO a -> (ReactHandle a b -> Bool -> b -> IO Bool) -> SF Identity a b -> IO (ReactHandle a b) Source #

Initialize a top-level reaction handle.

react :: ReactHandle a b -> (DTime, Maybe a) -> IO Bool Source #

Process a single input sample.

once :: Monad m => SF m (Event a) (Event a) Source #

Suppress all but the first event.

switch :: Monad m => SF m a (b, Event c) -> (c -> SF m a b) -> SF m a b Source #

Basic switch.

By default, the first signal function is applied. Whenever the second value in the pair actually is an event, the value carried by the event is used to obtain a new signal function to be applied *at that time and at future times*. Until that happens, the first value in the pair is produced in the output signal.

Important note: at the time of switching, the second signal function is applied immediately. If that second SF can also switch at time zero, then a double (nested) switch might take place. If the second SF refers to the first one, the switch might take place infinitely many times and never be resolved.

Remember: The continuation is evaluated strictly at the time of switching!

dSwitch :: Monad m => SF m a (b, Event c) -> (c -> SF m a b) -> SF m a b Source #

Switch with delayed observation.

By default, the first signal function is applied.

Whenever the second value in the pair actually is an event, the value carried by the event is used to obtain a new signal function to be applied *at future times*.

Until that happens, the first value in the pair is produced in the output signal.

Important note: at the time of switching, the second signal function is used immediately, but the current input is fed by it (even though the actual output signal value at time 0 is discarded).

If that second SF can also switch at time zero, then a double (nested) switch might take place. If the second SF refers to the first one, the switch might take place infinitely many times and never be resolved.

Remember: The continuation is evaluated strictly at the time of switching!

eventToMaybe :: Event a -> Maybe a Source #

Convert an Event into a Maybe value.

Both types are isomorphic, where a value containing an event is mapped to a Just, and NoEvent is mapped to Nothing. There is, however, a semantic difference: a signal carrying a Maybe may change constantly, but, for a signal carrying an Event, there should be a bounded frequency such that sampling the signal faster does not render more event occurrences.

arr2 :: Arrow a => (b -> c -> d) -> a (b, c) d Source #

Lift a binary function onto an arrow.

arr3 :: Arrow a => (b -> c -> d -> e) -> a (b, c, d) e Source #

Deprecated: The function arr3 is deprecated in BearRiver 0.15 and will be removed in future versions.

Lift a 3-ary function onto an arrow.

arr4 :: Arrow a => (b -> c -> d -> e -> f) -> a (b, c, d, e) f Source #

Deprecated: The function arr4 is deprecated in BearRiver 0.15 and will be removed in future versions.

Lift a 4-ary function onto an arrow.

arr5 :: Arrow a => (b -> c -> d -> e -> f -> g) -> a (b, c, d, e, f) g Source #

Deprecated: The function arr5 is deprecated in BearRiver 0.15 and will be removed in future versions.

Lift a 5-ary function onto an arrow.

identity :: Monad m => SF m a a Source #

Identity: identity = arr id

Using identity is preferred over lifting id, since the arrow combinators know how to optimise certain networks based on the transformations being applied.

constant :: Monad m => b -> SF m a b Source #

Identity: constant b = arr (const b)

Using constant is preferred over lifting const, since the arrow combinators know how to optimise certain networks based on the transformations being applied.

(-->) :: Monad m => b -> SF m a b -> SF m a b infixr 0 Source #

Initialization operator (cf. Lustre/Lucid Synchrone).

The output at time zero is the first argument, and from that point on it behaves like the signal function passed as second argument.

(-:>) :: Monad m => b -> SF m a b -> SF m a b infixr 0 Source #

Output pre-insert operator.

Insert a sample in the output, and from that point on, behave like the given sf.

(>--) :: Monad m => a -> SF m a b -> SF m a b infixr 0 Source #

Input initialization operator.

The input at time zero is the first argument, and from that point on it behaves like the signal function passed as second argument.

(>=-) :: Monad m => (a -> a) -> SF m a b -> SF m a b infixr 0 Source #

Transform initial input value.

Applies a transformation f only to the first input value at time zero.

initially :: Monad m => a -> SF m a a Source #

Override initial value of input signal.

provided :: Monad m => (a -> Bool) -> SF m a b -> SF m a b -> SF m a b Source #

Runs a signal function only when a given predicate is satisfied, otherwise runs the other signal function.

This is similar to ArrowChoice, except that this resets the SFs after each transition.

For example, the following integrates the incoming input numbers, using one integral if the numbers are even, and another if the input numbers are odd. Note how, every time we "switch", the old value of the integral is discarded.

>>> embed (provided (even . round) integral integral) (deltaEncode 1 [1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 2, 2 :: Double])
[0.0,1.0,2.0,0.0,2.0,4.0,0.0,1.0,2.0,0.0,2.0,4.0]

pause :: Monad m => b -> SF m a Bool -> SF m a b -> SF m a b Source #

Given a value in an accumulator (b), a predicate signal function (sfC), and a second signal function (sf), pause will produce the accumulator b if sfC input is True, and will transform the signal using sf otherwise. It acts as a pause with an accumulator for the moments when the transformation is paused.

edge :: Monad m => SF m Bool (Event ()) Source #

A rising edge detector. Useful for things like detecting key presses. It is initialised as up, meaning that events occurring at time 0 will not be detected.

snap :: Monad m => SF m a (Event a) Source #

Event source with a single occurrence at time 0. The value of the event is obtained by sampling the input at that time.

pre :: Monad m => SF m a a Source #

Uninitialized delay operator.

The output has an infinitesimal delay (1 sample), and the value at time zero is undefined.

fby :: Monad m => b -> SF m a b -> SF m a b infixr 0 Source #

Lucid-Synchrone-like initialized delay (read "followed by").

Initialized delay combinator, introducing an infinitesimal delay (one sample) in given SF, using the given argument to fill in the initial output at time zero.

The difference with iPre is that fby takes an SF as argument.

delay :: Monad m => Time -> a -> SF m a a Source #

Delay a signal by a fixed time t, using the second parameter to fill in the initial t seconds.

sscanPrim :: Monad m => (c -> a -> Maybe (c, b)) -> c -> b -> SF m a b Source #

Generic version of sscan, in which the auxiliary function produces an internal accumulator and an "held" output.

Applies a function point-wise, using the last known Just output to form the output, and next input accumulator. If the output is Nothing, the last known accumulators are used. This creates a well-formed loop based on a pure, auxiliary function.

noEvent :: Event a Source #

Make the NoEvent constructor available. Useful e.g. for initialization, ((-->) & friends), and it's easily available anyway (e.g. mergeEvents []).

noEventFst :: (Event a, b) -> (Event c, b) Source #

Suppress any event in the first component of a pair.

noEventSnd :: (a, Event b) -> (a, Event c) Source #

Suppress any event in the second component of a pair.

event :: a -> (b -> a) -> Event b -> a Source #

An event-based version of the maybe function.

fromEvent :: Event a -> a Source #

Extract the value from an event. Fails if there is no event.

isEvent :: Event a -> Bool Source #

Tests whether the input represents an actual event.

isNoEvent :: Event a -> Bool Source #

Negation of isEvent.

tag :: Event a -> b -> Event b infixl 8 Source #

Tags an (occurring) event with a value ("replacing" the old value).

Applicative-based definition: tag = ($>)

tagWith :: b -> Event a -> Event b Source #

Tags an (occurring) event with a value ("replacing" the old value). Same as tag with the arguments swapped.

Applicative-based definition: tagWith = (<$)

attach :: Event a -> b -> Event (a, b) infixl 8 Source #

Attaches an extra value to the value of an occurring event.

lMerge :: Event a -> Event a -> Event a infixl 6 Source #

Left-biased event merge (always prefer left event, if present).

rMerge :: Event a -> Event a -> Event a infixl 6 Source #

Right-biased event merge (always prefer right event, if present).

mergeBy :: (a -> a -> a) -> Event a -> Event a -> Event a Source #

Event merge parameterized by a conflict resolution function.

Applicative-based definition: mergeBy f le re = (f $ le * re) | le | re

mapMerge Source #

Arguments

:: (a -> c)

Mapping function used when first event is present.

-> (b -> c)

Mapping function used when second event is present.

-> (a -> b -> c)

Mapping function used when both events are present.

-> Event a

First event

-> Event b

Second event

-> Event c 

A generic event merge-map utility that maps event occurrences, merging the results. The first three arguments are mapping functions, the third of which will only be used when both events are present. Therefore, mergeBy = mapMerge id id.

Applicative-based definition: mapMerge lf rf lrf le re = (f $ le * re) | (lf $ le) | (rf $ re)

mergeEvents :: [Event a] -> Event a Source #

Merge a list of events; foremost event has priority.

Foldable-based definition: mergeEvents :: Foldable t => t (Event a) -> Event a mergeEvents = asum

catEvents :: [Event a] -> Event [a] Source #

Collect simultaneous event occurrences; no event if none.

joinE :: Event a -> Event b -> Event (a, b) infixl 7 Source #

Join (conjunction) of two events. Only produces an event if both events exist.

Applicative-based definition: joinE = liftA2 (,)

splitE :: Event (a, b) -> (Event a, Event b) Source #

Split event carrying pairs into two events.

filterE :: (a -> Bool) -> Event a -> Event a Source #

Filter out events that don't satisfy some predicate.

mapFilterE :: (a -> Maybe b) -> Event a -> Event b Source #

Combined event mapping and filtering. Note: since Event is a Functor, see fmap for a simpler version of this function with no filtering.

gate :: Event a -> Bool -> Event a infixl 8 Source #

Enable/disable event occurrences based on an external condition.

maybeToEvent :: Maybe a -> Event a Source #

Convert a maybe value into a event (Event is isomorphic to Maybe).

never :: Monad m => SF m a (Event b) Source #

Event source that never occurs.

now :: Monad m => b -> SF m a (Event b) Source #

Event source with a single occurrence at time 0. The value of the event is given by the function argument.

after Source #

Arguments

:: Monad m 
=> Time

The time q after which the event should be produced

-> b

Value to produce at that time

-> SF m a (Event b) 

Event source with a single occurrence at or as soon after (local) time q as possible.

afterEach :: Monad m => [(Time, b)] -> SF m a (Event b) Source #

Event source with consecutive occurrences at the given intervals. Should more than one event be scheduled to occur in any sampling interval, only the first will in fact occur to avoid an event backlog.

afterEachCat :: Monad m => [(Time, b)] -> SF m a (Event [b]) Source #

Event source with consecutive occurrences at the given intervals. Should more than one event be scheduled to occur in any sampling interval, the output list will contain all events produced during that interval.

delayEvent :: Monad m => Time -> SF m (Event a) (Event a) Source #

Delay for events. (Consider it a triggered after, hence basic.)

delayEventCat :: Monad m => Time -> SF m (Event a) (Event [a]) Source #

Delay an event by a given delta and catenate events that occur so closely so as to be inseparable.

iEdge :: Monad m => Bool -> SF m Bool (Event ()) Source #

A rising edge detector that can be initialized as up (True, meaning that events occurring at time 0 will not be detected) or down (False, meaning that events occurring at time 0 will be detected).

edgeTag :: Monad m => a -> SF m Bool (Event a) Source #

Like edge, but parameterized on the tag value.

edgeJust :: Monad m => SF m (Maybe a) (Event a) Source #

Edge detector particularized for detecting transitions on a Maybe signal from Nothing to Just.

edgeBy :: Monad m => (a -> a -> Maybe b) -> a -> SF m a (Event b) Source #

Edge detector parameterized on the edge detection function and initial state, i.e., the previous input sample. The first argument to the edge detection function is the previous sample, the second the current one.

notYet :: Monad m => SF m (Event a) (Event a) Source #

Suppression of initial (at local time 0) event.

takeEvents :: Monad m => Int -> SF m (Event a) (Event a) Source #

Suppress all but the first n events.

dropEvents :: Monad m => Int -> SF m (Event a) (Event a) Source #

Suppress first n events.

snapAfter :: Monad m => Time -> SF m a (Event a) Source #

Event source with a single occurrence at or as soon after (local) time tEv as possible. The value of the event is obtained by sampling the input a that time.

sample :: Monad m => Time -> SF m a (Event a) Source #

Sample a signal at regular intervals.

sampleWindow :: Monad m => Int -> Time -> SF m a (Event [a]) Source #

Window sampling.

First argument is the window length wl, second is the sampling interval t. The output list should contain (min (truncate (T/t) wl)) samples, where T is the time the signal function has been running. This requires some care in case of sparse sampling. In case of sparse sampling, the current input value is assumed to have been present at all points where sampling was missed.

recur :: Monad m => SF m a (Event b) -> SF m a (Event b) Source #

Makes an event source recurring by restarting it as soon as it has an occurrence.

andThen :: Monad m => SF m a (Event b) -> SF m a (Event b) -> SF m a (Event b) Source #

Apply the first SF until it produces an event, and, afterwards, switch to the second SF. This is just a convenience function, used to write what sometimes is more understandable switch-based code.

accumBy :: Monad m => (b -> a -> b) -> b -> SF m (Event a) (Event b) Source #

Accumulator parameterized by the accumulation function.

hold :: Monad m => a -> SF m (Event a) a Source #

Zero-order hold.

Converts a discrete-time signal into a continuous-time signal, by holding the last value until it changes in the input signal. The given parameter may be used for time zero, and until the first event occurs in the input signal, so hold is always well-initialized.

>>> embed (hold 1) (deltaEncode 0.1 [NoEvent, NoEvent, Event 2, NoEvent, Event 3, NoEvent])
[1,1,2,2,3,3]

dHold :: Monad m => a -> SF m (Event a) a Source #

Zero-order hold with a delay.

Converts a discrete-time signal into a continuous-time signal, by holding the last value until it changes in the input signal. The given parameter is used for time zero (until the first event occurs in the input signal), so dHold shifts the discrete input by an infinitesimal delay.

>>> embed (dHold 1) (deltaEncode 0.1 [NoEvent, NoEvent, Event 2, NoEvent, Event 3, NoEvent])
[1,1,1,2,2,3]

trackAndHold :: Monad m => a -> SF m (Maybe a) a Source #

Tracks input signal when available, holding the last value when the input is Nothing.

This behaves similarly to hold, but there is a conceptual difference, as it takes a signal of input Maybe a (for some a) and not Event.

>>> embed (trackAndHold 1) (deltaEncode 0.1 [Nothing, Nothing, Just 2, Nothing, Just 3, Nothing])
[1,1,2,2,3,3]

dTrackAndHold :: Monad m => a -> SF m (Maybe a) a Source #

Tracks input signal when available, holding the last value when the input is Nothing, with a delay.

This behaves similarly to hold, but there is a conceptual difference, as it takes a signal of input Maybe a (for some a) and not Event.

>>> embed (dTrackAndHold 1) (deltaEncode 0.1 [Nothing, Nothing, Just 2, Nothing, Just 3, Nothing])
[1,1,1,2,2,3]

accumHold :: Monad m => a -> SF m (Event (a -> a)) a Source #

Zero-order hold accumulator (always produces the last outputted value until an event arrives).

dAccumHold :: Monad m => a -> SF m (Event (a -> a)) a Source #

Zero-order hold accumulator with delayed initialization (always produces the last outputted value until an event arrives, but the very initial output is always the given accumulator).

accumHoldBy :: Monad m => (b -> a -> b) -> b -> SF m (Event a) b Source #

Zero-order hold accumulator parameterized by the accumulation function.

dAccumHoldBy :: Monad m => (b -> a -> b) -> b -> SF m (Event a) b Source #

Zero-order hold accumulator parameterized by the accumulation function with delayed initialization (initial output sample is always the given accumulator).

accumFilter :: Monad m => (c -> a -> (c, Maybe b)) -> c -> SF m (Event a) (Event b) Source #

Accumulator parameterized by the accumulator function with filtering, possibly discarding some of the input events based on whether the second component of the result of applying the accumulation function is Nothing or Just x for some x.

integral :: (Monad m, Fractional s, VectorSpace a s) => SF m a a Source #

Integration using the rectangle rule.

imIntegral :: (Fractional s, VectorSpace a s, Monad m) => a -> SF m a a Source #

"Immediate" integration (using the function's value at the current time).

trapezoidIntegral :: (Fractional s, VectorSpace a s, Monad m) => SF m a a Source #

Trapezoid integral (using the average between the value at the last time and the value at the current time).

impulseIntegral :: (Fractional k, VectorSpace a k, Monad m) => SF m (a, Event a) a Source #

Integrate the first input signal and add the discrete accumulation (sum) of the second, discrete, input signal.

derivative :: (Monad m, Fractional s, VectorSpace a s) => SF m a a Source #

A very crude version of a derivative. It simply divides the value difference by the time difference. Use at your own risk.

iterFrom :: Monad m => (a -> a -> DTime -> b -> b) -> b -> SF m a b Source #

Integrate using an auxiliary function that takes the current and the last input, the time between those samples, and the last output, and returns a new output.

loopPre :: MonadFix m => c -> SF m (a, c) (b, c) -> SF m a b Source #

Loop with an initial value for the signal being fed back.

loopIntegral :: (MonadFix m, Fractional s, VectorSpace c s) => SF m (a, c) (b, c) -> SF m a b Source #

Loop by integrating the second value in the pair and feeding the result back. Because the integral at time 0 is zero, this is always well defined.

noise :: (RandomGen g, Random b, Monad m) => g -> SF m a b Source #

Noise (random signal) with default range for type in question; based on "randoms".

noiseR :: (RandomGen g, Random b, Monad m) => (b, b) -> g -> SF m a b Source #

Noise (random signal) with specified range; based on "randomRs".

occasionally :: (RandomGen g, Monad m) => g -> Time -> b -> SF m a (Event b) Source #

Stochastic event source with events occurring on average once every tAvg seconds. However, no more than one event results from any one sampling interval in the case of relatively sparse sampling, thus avoiding an "event backlog" should sampling become more frequent at some later point in time.

sscan :: Monad m => (b -> a -> b) -> b -> SF m a b Source #

Applies a function point-wise, using the last output as next input. This creates a well-formed loop based on a pure, auxiliary function.

embedSynch :: forall m a b. (Monad m, MonadFail m) => SF m a b -> (a, [(DTime, Maybe a)]) -> SF m Double b Source #

Synchronous embedding. The embedded signal function is run on the supplied input and time stream at a given (but variable) ratio >= 0 to the outer time flow. When the ratio is 0, the embedded signal function is paused.

deltaEncode :: Eq a => DTime -> [a] -> (a, [(DTime, Maybe a)]) Source #

Spaces a list of samples by a fixed time delta, avoiding unnecessary samples when the input has not changed since the last sample.

deltaEncodeBy :: (a -> a -> Bool) -> DTime -> [a] -> (a, [(DTime, Maybe a)]) Source #

deltaEncode parameterized by the equality test.

evalAtZero :: SF Identity a b -> a -> (b, SF Identity a b) Source #

Evaluate an SF, and return an output and an initialized SF.

WARN: Do not use this function for standard simulation. This function is intended only for debugging/testing. Apart from being potentially slower and consuming more memory, it also breaks the FRP abstraction by making samples discrete and step based.

evalAt :: SF Identity a b -> DTime -> a -> (b, SF Identity a b) Source #

Evaluate an initialized SF, and return an output and a continuation.

WARN: Do not use this function for standard simulation. This function is intended only for debugging/testing. Apart from being potentially slower and consuming more memory, it also breaks the FRP abstraction by making samples discrete and step based.

evalFuture :: SF Identity a b -> a -> DTime -> (b, SF Identity a b) Source #

Given a signal function and time delta, it moves the signal function into the future, returning a new uninitialized SF and the initial output.

While the input sample refers to the present, the time delta refers to the future (or to the time between the current sample and the next sample).

WARN: Do not use this function for standard simulation. This function is intended only for debugging/testing. Apart from being potentially slower and consuming more memory, it also breaks the FRP abstraction by making samples discrete and step based.

rSwitch :: Monad m => SF m a b -> SF m (a, Event (SF m a b)) b Source #

Recurring switch.

Uses the given SF until an event comes in the input, in which case the SF in the event is turned on, until the next event comes in the input, and so on.

See https://wiki.haskell.org/Yampa#Switches for more information on how this switch works.

drSwitch :: Monad m => SF m a b -> SF m (a, Event (SF m a b)) b Source #

Recurring switch with delayed observation.

Uses the given SF until an event comes in the input, in which case the SF in the event is turned on, until the next event comes in the input, and so on.

Uses decoupled switch (dSwitch).

See https://wiki.haskell.org/Yampa#Switches for more information on how this switch works.

kSwitch :: Monad m => SF m a b -> SF m (a, b) (Event c) -> (SF m a b -> c -> SF m a b) -> SF m a b Source #

Call-with-current-continuation switch.

Applies the first SF until the input signal and the output signal, when passed to the second SF, produce an event, in which case the original SF and the event are used to build an new SF to switch into.

See https://wiki.haskell.org/Yampa#Switches for more information on how this switch works.

dkSwitch :: Monad m => SF m a b -> SF m (a, b) (Event c) -> (SF m a b -> c -> SF m a b) -> SF m a b Source #

kSwitch with delayed observation.

Applies the first SF until the input signal and the output signal, when passed to the second SF, produce an event, in which case the original SF and the event are used to build an new SF to switch into.

The switch is decoupled (dSwitch).

See https://wiki.haskell.org/Yampa#Switches for more information on how this switch works.

parB :: Monad m => [SF m a b] -> SF m a [b] Source #

Spatial parallel composition of a signal function collection. Given a collection of signal functions, it returns a signal function that broadcasts its input signal to every element of the collection, to return a signal carrying a collection of outputs. See par.

For more information on how parallel composition works, check https://www.antonycourtney.com/pubs/hw03.pdf

pSwitchB :: (Functor m, Monad m, Traversable col, Functor col) => col (SF m a b) -> SF m (a, col b) (Event c) -> (col (SF m a b) -> c -> SF m a (col b)) -> SF m a (col b) Source #

Parallel switch (dynamic collection of signal functions spatially composed in parallel) with broadcasting. See pSwitch.

For more information on how parallel composition works, check https://www.antonycourtney.com/pubs/hw03.pdf

dpSwitchB :: (Functor m, Monad m, Traversable col) => col (SF m a b) -> SF m (a, col b) (Event c) -> (col (SF m a b) -> c -> SF m a (col b)) -> SF m a (col b) Source #

Decoupled parallel switch with broadcasting (dynamic collection of signal functions spatially composed in parallel). See dpSwitch.

For more information on how parallel composition works, check https://www.antonycourtney.com/pubs/hw03.pdf

rpSwitchB :: (Functor m, Monad m, Functor col, Traversable col) => col (SF m a b) -> SF m (a, Event (col (SF m a b) -> col (SF m a b))) (col b) Source #

Recurring parallel switch with broadcasting.

Uses the given collection of SFs, until an event comes in the input, in which case the function in the Event is used to transform the collections of SF to be used with rpSwitch again, until the next event comes in the input, and so on.

Broadcasting is used to decide which subpart of the input goes to each SF in the collection.

See rpSwitch.

For more information on how parallel composition works, check https://www.antonycourtney.com/pubs/hw03.pdf

drpSwitchB :: (Functor m, Monad m, Functor col, Traversable col) => col (SF m a b) -> SF m (a, Event (col (SF m a b) -> col (SF m a b))) (col b) Source #

Decoupled recurring parallel switch with broadcasting.

Uses the given collection of SFs, until an event comes in the input, in which case the function in the Event is used to transform the collections of SF to be used with rpSwitch again, until the next event comes in the input, and so on.

Broadcasting is used to decide which subpart of the input goes to each SF in the collection.

This is the decoupled version of rpSwitchB.

For more information on how parallel composition works, check https://www.antonycourtney.com/pubs/hw03.pdf

pSwitch Source #

Arguments

:: (Functor m, Monad m, Traversable col, Functor col) 
=> (forall sf. a -> col sf -> col (b, sf))

Routing function: determines the input to each signal function in the collection. IMPORTANT! The routing function has an obligation to preserve the structure of the signal function collection.

-> col (SF m b c)

Signal function collection.

-> SF m (a, col c) (Event d)

Signal function generating the switching event.

-> (col (SF m b c) -> d -> SF m a (col c))

Continuation to be invoked once event occurs.

-> SF m a (col c) 

Parallel switch parameterized on the routing function. This is the most general switch from which all other (non-delayed) switches in principle can be derived. The signal function collection is spatially composed in parallel and run until the event signal function has an occurrence. Once the switching event occurs, all signal function are "frozen" and their continuations are passed to the continuation function, along with the event value.

dpSwitch Source #

Arguments

:: (Monad m, Traversable col) 
=> (forall sf. a -> col sf -> col (b, sf))

Routing function. Its purpose is to pair up each running signal function in the collection maintained by dpSwitch with the input it is going to see at each point in time. All the routing function can do is specify how the input is distributed.

-> col (SF m b c)

Initial collection of signal functions.

-> SF m (a, col c) (Event d)

Signal function that observes the external input signal and the output signals from the collection in order to produce a switching event.

-> (col (SF m b c) -> d -> SF m a (col c))

The fourth argument is a function that is invoked when the switching event occurs, yielding a new signal function to switch into based on the collection of signal functions previously running and the value carried by the switching event. This allows the collection to be updated and then switched back in, typically by employing dpSwitch again.

-> SF m a (col c) 

Parallel switch with delayed observation parameterized on the routing function.

The collection argument to the function invoked on the switching event is of particular interest: it captures the continuations of the signal functions running in the collection maintained by dpSwitch at the time of the switching event, thus making it possible to preserve their state across a switch. Since the continuations are plain, ordinary signal functions, they can be resumed, discarded, stored, or combined with other signal functions.

rpSwitch Source #

Arguments

:: (Functor m, Monad m, Functor col, Traversable col) 
=> (forall sf. a -> col sf -> col (b, sf))

Routing function: determines the input to each signal function in the collection. IMPORTANT! The routing function has an obligation to preserve the structure of the signal function collection.

-> col (SF m b c)

Initial signal function collection.

-> SF m (a, Event (col (SF m b c) -> col (SF m b c))) (col c) 

Recurring parallel switch parameterized on the routing function.

Uses the given collection of SFs, until an event comes in the input, in which case the function in the Event is used to transform the collections of SF to be used with rpSwitch again, until the next event comes in the input, and so on.

The routing function is used to decide which subpart of the input goes to each SF in the collection.

This is the parallel version of rSwitch.

drpSwitch Source #

Arguments

:: (Functor m, Monad m, Functor col, Traversable col) 
=> (forall sf. a -> col sf -> col (b, sf))

Routing function: determines the input to each signal function in the collection. IMPORTANT! The routing function has an obligation to preserve the structure of the signal function collection.

-> col (SF m b c)

Initial signal function collection.

-> SF m (a, Event (col (SF m b c) -> col (SF m b c))) (col c) 

Recurring parallel switch with delayed observation parameterized on the routing function.

Uses the given collection of SFs, until an event comes in the input, in which case the function in the Event is used to transform the collections of SF to be used with rpSwitch again, until the next event comes in the input, and so on.

The routing function is used to decide which subpart of the input goes to each SF in the collection.

This is the parallel version of drSwitch.

parZ :: (Functor m, Monad m) => [SF m a b] -> SF m [a] [b] Source #

Parallel composition of a list of SFs.

Given a list of SFs, returns an SF that takes a list of inputs, applies each SF to each input in order, and returns the SFs' outputs.

>>> embed (parZ [arr (+1), arr (+2)]) (deltaEncode 0.1 [[0, 0], [1, 1]])
[[1,2],[2,3]]

If there are more SFs than inputs, an exception is thrown.

>>> embed (parZ [arr (+1), arr (+1), arr (+2)]) (deltaEncode 0.1 [[0, 0], [1, 1]])
[[1,1,*** Exception: FRP.Yampa.Switches.parZ: Input list too short.

If there are more inputs than SFs, the unused inputs are ignored.

>>> embed (parZ [arr (+1)]) (deltaEncode 0.1 [[0, 0], [1, 1]])
[[1],[2]]

pSwitchZ :: (Functor m, Monad m) => [SF m a b] -> SF m ([a], [b]) (Event c) -> ([SF m a b] -> c -> SF m [a] [b]) -> SF m [a] [b] Source #

Parallel switch (dynamic collection of signal functions spatially composed in parallel). See pSwitch.

For more information on how parallel composition works, check https://www.antonycourtney.com/pubs/hw03.pdf

dpSwitchZ :: (Functor m, Monad m) => [SF m a b] -> SF m ([a], [b]) (Event c) -> ([SF m a b] -> c -> SF m [a] [b]) -> SF m [a] [b] Source #

Decoupled parallel switch with broadcasting (dynamic collection of signal functions spatially composed in parallel). See dpSwitch.

For more information on how parallel composition works, check https://www.antonycourtney.com/pubs/hw03.pdf

rpSwitchZ :: (Functor m, Monad m) => [SF m a b] -> SF m ([a], Event ([SF m a b] -> [SF m a b])) [b] Source #

Recurring parallel switch with "zip" routing.

Uses the given list of SFs, until an event comes in the input, in which case the function in the Event is used to transform the list of SF to be used with rpSwitchZ again, until the next event comes in the input, and so on.

Zip routing is used to decide which subpart of the input goes to each SF in the list.

See rpSwitch.

For more information on how parallel composition works, check https://www.antonycourtney.com/pubs/hw03.pdf

drpSwitchZ :: (Functor m, Monad m) => [SF m a b] -> SF m ([a], Event ([SF m a b] -> [SF m a b])) [b] Source #

Decoupled recurring parallel switch with "zip" routing.

Uses the given list of SFs, until an event comes in the input, in which case the function in the Event is used to transform the list of SF to be used with rpSwitchZ again, until the next event comes in the input, and so on.

Zip routing is used to decide which subpart of the input goes to each SF in the list.

See rpSwitchZ and drpSwitch.

For more information on how parallel composition works, check https://www.antonycourtney.com/pubs/hw03.pdf

parC :: Monad m => SF m a b -> SF m [a] [b] Source #

Apply an SF to every element of a list.

Example:

>>> embed (parC integral) (deltaEncode 0.1 [[1, 2], [2, 4], [3, 6], [4.0, 8.0 :: Float]])
[[0.0,0.0],[0.1,0.2],[0.3,0.6],[0.6,1.2]]

The number of SFs or expected inputs is determined by the first input list, and not expected to vary over time.

If more inputs come in a subsequent list, they are ignored.

>>> embed (parC (arr (+1))) (deltaEncode 0.1 [[0], [1, 1], [3, 4], [6, 7, 8], [1, 1], [0, 0], [1, 9, 8]])
[[1],[2],[4],[7],[2],[1],[2]]

If less inputs come in a subsequent list, an exception is thrown.

>>> embed (parC (arr (+1))) (deltaEncode 0.1 [[0, 0], [1, 1], [3, 4], [6, 7, 8], [1, 1], [0, 0], [1, 9, 8]])
[[1,1],[2,2],[4,5],[7,8],[2,2],[1,1],[2,10]]

mkTask :: Monad m => SF m a (b, Event c) -> Task m a b c Source #

Creates a Task from an SF that returns, as a second output, an Event when the SF terminates. See switch.

runTask :: Monad m => Task m a b c -> SF m a (Either b c) Source #

Runs a task.

The output from the resulting signal transformer is tagged with Left while the underlying task is running. Once the task has terminated, the output goes constant with the value Right x, where x is the value of the terminating event.

runTask_ :: Monad m => Task m a b c -> SF m a b Source #

Runs a task that never terminates.

The output becomes undefined once the underlying task has terminated.

Convenience function for tasks which are known not to terminate.

taskToSF :: Monad m => Task m a b c -> SF m a (b, Event c) Source #

Creates an SF that represents an SF and produces an event when the task terminates, and otherwise produces just an output.

constT :: Monad m => b -> Task m a b c Source #

Non-terminating task with constant output b.

sleepT :: Monad m => Time -> b -> Task m a b () Source #

Sleeps for t seconds with constant output b.

snapT :: Monad m => Task m a b a Source #

Takes a "snapshot" of the input and terminates immediately with the input value as the result.

No time passes; therefore, the following must hold:

snapT >> snapT = snapT

timeOut :: Monad m => Task m a b c -> Time -> Task m a b (Maybe c) infixl 0 Source #

Impose a time out on a task.

abortWhen :: Monad m => Task m a b c -> SF m a (Event d) -> Task m a b (Either c d) infixl 0 Source #

Run a "guarding" event source (SF m a (Event b)) in parallel with a (possibly non-terminating) task.

The task will be aborted at the first occurrence of the event source (if it has not terminated itself before that).

Useful for separating sequencing and termination concerns. E.g. we can do something "useful", but in parallel watch for a (exceptional) condition which should terminate that activity, without having to check for that condition explicitly during each and every phase of the activity.

Example: tsk abortWhen lbp

localTime :: Monad m => SF m a Time Source #

Outputs the time passed since the signal function instance was started.

boolToEvent :: Bool -> Event () Source #

Create an event if a Bool is True.

type SF = SF Identity Source #

Signal function (conceptually, a function between signals that respects causality).

type FutureSF = SF Identity Source #

Future signal function (conceptually, a function between future signals that respects causality).

A future signal is a signal that is only defined for positive times.

embed :: SF a b -> (a, [(DTime, Maybe a)]) -> [b] Source #

Given a signal function and a pair with an initial input sample for the input signal, and a list of sampling times, possibly with new input samples at those times, it produces a list of output samples.

This is a simplified, purely-functional version of reactimate.

reactimate Source #

Arguments

:: Monad m 
=> m a

Initialization action

-> (Bool -> m (DTime, Maybe a))

Input sensing action

-> (Bool -> b -> m Bool)

Actuation (output processing) action

-> SF a b

Signal function

-> m () 

Convenience function to run a signal function indefinitely, using actions to obtain new input and process the output.

This function first runs the initialization action, which provides the initial input for the signal transformer at time 0.

Afterwards, an input sensing action is used to obtain new input (if any) and the time since the last iteration. The argument to the input sensing function indicates if it can block. If no new input is received, it is assumed to be the same as in the last iteration.

After applying the signal function to the input, the actuation action is executed. The first argument indicates if the output has changed, the second gives the actual output). Actuation functions may choose to ignore the first argument altogether. This action should return True if the reactimation must stop, and False if it should continue.

Note that this becomes the program's main loop, which makes using this function incompatible with GLUT, Gtk and other graphics libraries. It may also impose a sizeable constraint in larger projects in which different subparts run at different time steps. If you need to control the main loop yourself for these or other reasons, use reactInit and react.