{-# LANGUAGE Arrows #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
module FRP.Rhine.Type where
import Data.MonadicStreamFunction
import FRP.Rhine.Reactimation.ClockErasure
import FRP.Rhine.Clock
import FRP.Rhine.Clock.Proxy
import FRP.Rhine.SN
data Rhine m cl a b = Rhine
{ Rhine m cl a b -> SN m cl a b
sn :: SN m cl a b
, Rhine m cl a b -> cl
clock :: cl
}
instance GetClockProxy cl => ToClockProxy (Rhine m cl a b) where
type Cl (Rhine m cl a b) = cl
eraseClock
:: (Monad m, Clock m cl, GetClockProxy cl)
=> Rhine m cl a b
-> m (MSF m a (Maybe b))
eraseClock :: Rhine m cl a b -> m (MSF m a (Maybe b))
eraseClock Rhine {cl
SN m cl a b
clock :: cl
sn :: SN m cl a b
clock :: forall (m :: Type -> Type) cl a b. Rhine m cl a b -> cl
sn :: forall (m :: Type -> Type) cl a b. Rhine m cl a b -> SN m cl a b
..} = do
(MSF m () (Time cl, Tag cl)
runningClock, Time cl
initTime) <- cl -> m (MSF m () (Time cl, Tag cl), Time cl)
forall (m :: Type -> Type) cl.
Clock m cl =>
cl -> RunningClockInit m (Time cl) (Tag cl)
initClock cl
clock
MSF m a (Maybe b) -> m (MSF m a (Maybe b))
forall (m :: Type -> Type) a. Monad m => a -> m a
return (MSF m a (Maybe b) -> m (MSF m a (Maybe b)))
-> MSF m a (Maybe b) -> m (MSF m a (Maybe b))
forall a b. (a -> b) -> a -> b
$ proc a
a -> do
(Time cl
time, Tag cl
tag) <- MSF m () (Time cl, Tag cl)
runningClock -< ()
Time cl
-> SN m cl a b -> MSF m (Time cl, Tag cl, Maybe a) (Maybe b)
forall (m :: Type -> Type) cl a b.
(Monad m, Clock m cl, GetClockProxy cl) =>
Time cl
-> SN m cl a b -> MSF m (Time cl, Tag cl, Maybe a) (Maybe b)
eraseClockSN Time cl
initTime SN m cl a b
sn -< (Time cl
time, Tag cl
tag, a
a a -> Maybe (Tag (In cl)) -> Maybe a
forall (f :: Type -> Type) a b. Functor f => a -> f b -> f a
<$ ClockProxy cl -> Tag cl -> Maybe (Tag (In cl))
forall cl. ClockProxy cl -> Tag cl -> Maybe (Tag (In cl))
inTag (SN m cl a b -> ClockProxy (Cl (SN m cl a b))
forall a. ToClockProxy a => a -> ClockProxy (Cl a)
toClockProxy SN m cl a b
sn) Tag cl
tag)