Skip to content

Commit

Permalink
Inline more library functions
Browse files Browse the repository at this point in the history
  • Loading branch information
turion committed Nov 27, 2024
1 parent c1a83ee commit ba7a69d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions automaton/src/Data/Automaton.hs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ 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))
Expand Down Expand Up @@ -519,10 +525,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
Expand Down
1 change: 1 addition & 0 deletions rhine/src/FRP/Rhine/Clock/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ genTimeInfo _ initialTime = proc (absolute, tag) -> do
, sinceInit = absolute `diffTime` initialTime
, ..
}
{-# INLINE genTimeInfo #-}

0 comments on commit ba7a69d

Please sign in to comment.