Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SN GADT in favour of inlinable functions #348

Merged
merged 7 commits into from
Nov 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Inlines
turion committed Nov 29, 2024
commit 78f87be6814ec82fb046ca9333fccf19fc3ed3ef
8 changes: 8 additions & 0 deletions rhine/src/FRP/Rhine/Reactimation/ClockErasure.hs
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ instance (GetClockProxy cl) => ToClockProxy (SN m cl a b) where

eraseClockSN :: Time cl -> SN m cl a b -> (Automaton m (Time cl, Tag cl, Maybe a) (Maybe b))
eraseClockSN time = flip runReader time . getSN
{-# INLINE eraseClockSN #-}

-- A synchronous signal network is run by erasing the clock from the clocked signal function.
synchronous ::
@@ -59,6 +60,7 @@ synchronous ::
synchronous clsf = SN $ reader $ \initialTime -> proc (time, tag, Just a) -> do
b <- eraseClockClSF (getClockProxy @cl) initialTime clsf -< (time, tag, a)
returnA -< Just b
{-# INLINE synchronous #-}

-- A sequentially composed signal network may either be triggered in its first component,
-- or its second component. In either case,
@@ -101,11 +103,13 @@ sequential sn1 resBuf sn2 = SN $ reader $ \initialTime ->
returnA -< Nothing
Right tagR -> do
eraseClockSN initialTime sn2 -< (time, tagR, join maybeC)
{-# INLINE sequential #-}

parallel snL snR = SN $ reader $ \initialTime -> proc (time, tag, maybeA) -> do
case tag of
Left tagL -> eraseClockSN initialTime snL -< (time, tagL, maybeA)
Right tagR -> eraseClockSN initialTime snR -< (time, tagR, maybeA)
{-# INLINE parallel #-}

postcompose sn clsf = SN $ reader $ \initialTime ->
let
@@ -114,6 +118,7 @@ postcompose sn clsf = SN $ reader $ \initialTime ->
proc input@(time, tag, _) -> do
bMaybe <- eraseClockSN initialTime sn -< input
mapMaybeS $ eraseClockClSF (outProxy proxy) initialTime clsf -< (time,,) <$> outTag proxy tag <*> bMaybe
{-# INLINE postcompose #-}

precompose clsf sn = SN $ reader $ \initialTime ->
let
@@ -122,6 +127,7 @@ precompose clsf sn = SN $ reader $ \initialTime ->
proc (time, tag, aMaybe) -> do
bMaybe <- mapMaybeS $ eraseClockClSF (inProxy proxy) initialTime clsf -< (time,,) <$> inTag proxy tag <*> aMaybe
eraseClockSN initialTime sn -< (time, tag, bMaybe)
{-# INLINE precompose #-}

feedbackSN ResamplingBuffer {buffer, put, get} sn = SN $ reader $ \initialTime ->
let
@@ -143,6 +149,8 @@ feedbackSN ResamplingBuffer {buffer, put, get} sn = SN $ reader $ \initialTime -
timeInfo <- genTimeInfo (outProxy proxy) initialTime -< (time, tagOut)
buf'' <- arrM $ uncurry $ uncurry put -< ((timeInfo, d), buf')
returnA -< (Just b, buf'')
{-# INLINE feedbackSN #-}

firstResampling sn buf = SN $ reader $ \initialTime ->
let
proxy = toClockProxy sn