{-# LANGUAGE GADTs #-}
module FRP.Rhine.SN.Combinators where
import FRP.Rhine.ClSF.Core
import FRP.Rhine.ResamplingBuffer.Util
import FRP.Rhine.Schedule
import FRP.Rhine.SN
(>>>^)
:: Monad m
=> SN m cl a b
-> (b -> c)
-> SN m cl a c
Synchronous clsf >>>^ f = Synchronous $ clsf >>^ f
Sequential sn1 rb sn2 >>>^ f = Sequential sn1 rb $ sn2 >>>^ f
Parallel sn1 sn2 >>>^ f = Parallel (sn1 >>>^ f) (sn2 >>>^ f)
(^>>>)
:: Monad m
=> (a -> b)
-> SN m cl b c
-> SN m cl a c
f ^>>> Synchronous clsf = Synchronous $ f ^>> clsf
f ^>>> Sequential sn1 rb sn2 = Sequential (f ^>>> sn1) rb sn2
f ^>>> Parallel sn1 sn2 = Parallel (f ^>>> sn1) (f ^>>> sn2)
(****)
:: Monad m
=> SN m cl a b
-> SN m cl c d
-> SN m cl (a, c) (b, d)
Synchronous clsf1 **** Synchronous clsf2 = Synchronous $ clsf1 *** clsf2
Sequential sn11 rb1 sn12 **** Sequential sn21 rb2 sn22 = Sequential sn1 rb sn2
where
sn1 = sn11 **** sn21
sn2 = sn12 **** sn22
rb = rb1 *-* rb2
Parallel sn11 sn12 **** Parallel sn21 sn22
= Parallel (sn11 **** sn21) (sn12 **** sn22)
_ **** _ = error "Impossible pattern in ****"
(||||)
:: ( Monad m, Clock m clL, Clock m clR
, Time clL ~ Time clR
, Time clL ~ Time (Out clL), Time clL ~ Time (In clL)
, Time clR ~ Time (Out clR), Time clR ~ Time (In clR)
)
=> SN m clL a b
-> SN m clR a b
-> SN m (ParClock m clL clR) a b
(||||) = Parallel
(++++)
:: ( Monad m, Clock m clL, Clock m clR
, Time clL ~ Time clR
, Time clL ~ Time (Out clL), Time clL ~ Time (In clL)
, Time clR ~ Time (Out clR), Time clR ~ Time (In clR)
)
=> SN m clL a b
-> SN m clR a c
-> SN m (ParClock m clL clR) a (Either b c)
snL ++++ snR = (snL >>>^ Left) |||| (snR >>>^ Right)