From 2d9db231af468509df4ab9f68c07238edc03f4f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20B=C3=A4renz?= Date: Fri, 2 Aug 2024 16:43:05 +0200 Subject: [PATCH] Inline more library functions --- automaton/src/Data/Automaton.hs | 9 +++++++++ rhine/src/FRP/Rhine/Clock/Util.hs | 1 + 2 files changed, 10 insertions(+) diff --git a/automaton/src/Data/Automaton.hs b/automaton/src/Data/Automaton.hs index f97ddfc6..5eff8869 100644 --- a/automaton/src/Data/Automaton.hs +++ b/automaton/src/Data/Automaton.hs @@ -257,6 +257,13 @@ instance (Monad m) => ArrowChoice (Automaton m) where right (Automaton (Stateless ma)) = Automaton $! Stateless $! ReaderT $! either (pure . Left) (fmap Right . runReaderT ma) {-# INLINE right #-} + f ||| g = f +++ g >>> arr untag + where + untag (Left x) = x + untag (Right y) = y + + {-# INLINE (|||) #-} + -- | Caution, this can make your program hang. Try to use 'feedback' or 'unfold' where possible, or combine 'loop' with 'delay'. instance (MonadFix m) => ArrowLoop (Automaton m) where loop (Automaton (Stateless ma)) = Automaton $! Stateless $! ReaderT (\b -> fst <$> mfix ((. snd) $ ($ b) $ curry $ runReaderT ma)) @@ -514,10 +521,12 @@ sumS = sumFrom zeroVector -- | Sum up all inputs so far, initialised at 0. sumN :: (Monad m, Num a) => Automaton m a a sumN = arr Sum >>> mappendS >>> arr getSum +{-# INLINE sumN #-} -- | Count the natural numbers, beginning at 1. count :: (Num n, Monad m) => Automaton m a n count = feedback 0 $! arr (\(_, n) -> let n' = n + 1 in (n', n')) +{-# INLINE count #-} -- | Remembers the last 'Just' value, defaulting to the given initialisation value. lastS :: (Monad m) => a -> Automaton m (Maybe a) a diff --git a/rhine/src/FRP/Rhine/Clock/Util.hs b/rhine/src/FRP/Rhine/Clock/Util.hs index 0f95f960..a7690049 100644 --- a/rhine/src/FRP/Rhine/Clock/Util.hs +++ b/rhine/src/FRP/Rhine/Clock/Util.hs @@ -35,3 +35,4 @@ genTimeInfo _ initialTime = proc (absolute, tag) -> do , sinceInit = absolute `diffTime` initialTime , .. } +{-# INLINE genTimeInfo #-}