packages feed

bearriver 0.14.5 → 0.14.6

raw patch · 5 files changed

+128/−53 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- FRP.BearRiver: derivative :: (Monad m, Fractional s, VectorSpace a s) => SF m a a
- FRP.BearRiver: derivativeFrom :: (Monad m, Fractional s, VectorSpace a s) => a -> SF m a a
- FRP.BearRiver: integral :: (Monad m, Fractional s, VectorSpace a s) => SF m a a
- FRP.BearRiver: integralFrom :: (Monad m, Fractional s, VectorSpace a s) => a -> SF m a a
- FRP.BearRiver: iterFrom :: Monad m => (a -> a -> DTime -> b -> b) -> b -> SF m a b
- FRP.BearRiver: localTime :: Monad m => SF m a Time
- FRP.BearRiver: time :: Monad m => SF m a Time
- FRP.Yampa: derivativeFrom :: (Monad m, Fractional s, VectorSpace a s) => a -> SF m a a
- FRP.Yampa: integralFrom :: (Monad m, Fractional s, VectorSpace a s) => a -> SF m a a
+ FRP.BearRiver.Integration: derivative :: (Monad m, Fractional s, VectorSpace a s) => SF m a a
+ FRP.BearRiver.Integration: integral :: (Monad m, Fractional s, VectorSpace a s) => SF m a a
+ FRP.BearRiver.Integration: iterFrom :: Monad m => (a -> a -> DTime -> b -> b) -> b -> SF m a b
+ FRP.BearRiver.Time: localTime :: Monad m => SF m a Time
+ FRP.BearRiver.Time: time :: Monad m => SF m a Time

Files

CHANGELOG view
@@ -1,3 +1,8 @@+2023-12-21 Ivan Perez <ivan.perez@keera.co.uk>+        * Version bump (0.14.6) (#395).+        * Offer all definitions from FRP.Yampa.Time (#391).+        * Mark package as uncurated (#394).+ 2023-10-21 Ivan Perez <ivan.perez@keera.co.uk>         * Version bump (0.14.5) (#388).         * Offer all definitions from FRP.Yampa.Event (#380).
bearriver.cabal view
@@ -30,7 +30,7 @@ build-type:    Simple  name:          bearriver-version:       0.14.5+version:       0.14.6 author:        Ivan Perez, Manuel Bärenz maintainer:    ivan.perez@keera.co.uk homepage:      https://github.com/ivanperez-keera/dunai@@ -63,6 +63,9 @@   large applications.  +x-curation: uncurated++ extra-source-files:   CHANGELOG @@ -82,8 +85,10 @@     FRP.BearRiver.Delays     FRP.BearRiver.Event     FRP.BearRiver.EventS+    FRP.BearRiver.Integration     FRP.BearRiver.Scan     FRP.BearRiver.Switches+    FRP.BearRiver.Time     FRP.Yampa    other-modules:
src/FRP/BearRiver.hs view
@@ -42,26 +42,16 @@ import           FRP.BearRiver.Delays                    as X import           FRP.BearRiver.Event                     as X import           FRP.BearRiver.EventS                    as X+import           FRP.BearRiver.Integration               as X import           FRP.BearRiver.InternalCore              as X import           FRP.BearRiver.Scan                      as X import           FRP.BearRiver.Switches                  as X+import           FRP.BearRiver.Time                      as X  -- Internal imports (dunai, instances) import Data.MonadicStreamFunction.Instances.ArrowLoop () -- not needed, just                                                          -- re-exported --- * Signal functions---- ** Basic signal functions---- | Outputs the time passed since the signal function instance was started.-localTime :: Monad m => SF m a Time-localTime = constant 1.0 >>> integral---- | Alternative name for localTime.-time :: Monad m => SF m a Time-time = localTime- -- * Events  -- | Apply an 'MSF' to every input. Freezes temporarily if the input is@@ -124,46 +114,6 @@ -- | Loop with an initial value for the signal being fed back. loopPre :: Monad m => c -> SF m (a, c) (b, c) -> SF m a b loopPre = feedback---- * Integration and differentiation---- | Integration using the rectangle rule.-integral :: (Monad m, Fractional s, VectorSpace a s) => SF m a a-integral = integralFrom zeroVector---- | Integrate using an auxiliary function that takes the current and the last--- input, the time between those samples, and the last output, and returns a--- new output.-integralFrom :: (Monad m, Fractional s, VectorSpace a s) => a -> SF m a a-integralFrom a0 = proc a -> do-  dt <- constM ask        -< ()-  accumulateWith (^+^) a0 -< realToFrac dt *^ a---- | A very crude version of a derivative. It simply divides the value--- difference by the time difference. Use at your own risk.-derivative :: (Monad m, Fractional s, VectorSpace a s) => SF m a a-derivative = derivativeFrom zeroVector---- | A very crude version of a derivative. It simply divides the value--- difference by the time difference. Use at your own risk.------ Starts from a given value for the input signal at time zero.-derivativeFrom :: (Monad m, Fractional s, VectorSpace a s) => a -> SF m a a-derivativeFrom a0 = proc a -> do-  dt   <- constM ask  -< ()-  aOld <- MSF.iPre a0 -< a-  returnA             -< (a ^-^ aOld) ^/ realToFrac dt---- | Integrate using an auxiliary function that takes the current and the last--- input, the time between those samples, and the last output, and returns a--- new output.---- NOTE: BUG in this function, it needs two a's but we can only provide one-iterFrom :: Monad m => (a -> a -> DTime -> b -> b) -> b -> SF m a b-iterFrom f b = MSF $ \a -> do-  dt <- ask-  let b' = f a a dt b-  return (b, iterFrom f b')  -- * Noise (random signal) sources and stochastic event sources 
+ src/FRP/BearRiver/Integration.hs view
@@ -0,0 +1,71 @@+{-# LANGUAGE Arrows #-}+-- |+-- Copyright  : (c) Ivan Perez, 2019-2023+--              (c) Ivan Perez and Manuel Baerenz, 2016-2018+-- License    : BSD3+-- Maintainer : ivan.perez@keera.co.uk+--+-- Implementation of integrals and derivatives using Monadic Stream Processing+-- library.+module FRP.BearRiver.Integration+    (+      -- * Integration+      integral++      -- * Differentiation+    , derivative+    , iterFrom+    )+  where++-- External imports+import Control.Arrow    (returnA)+import Data.VectorSpace (VectorSpace, zeroVector, (*^), (^+^), (^-^), (^/))++-- Internal imports (dunai)+import Control.Monad.Trans.MSF                 (ask)+import Data.MonadicStreamFunction              (accumulateWith, constM, iPre)+import Data.MonadicStreamFunction.InternalCore (MSF (MSF))++-- Internal imports+import FRP.BearRiver.InternalCore (DTime, SF)++-- * Integration and differentiation++-- | Integration using the rectangle rule.+integral :: (Monad m, Fractional s, VectorSpace a s) => SF m a a+integral = integralFrom zeroVector++-- | Integrate using an auxiliary function that takes the current and the last+-- input, the time between those samples, and the last output, and returns a+-- new output.+integralFrom :: (Monad m, Fractional s, VectorSpace a s) => a -> SF m a a+integralFrom a0 = proc a -> do+  dt <- constM ask        -< ()+  accumulateWith (^+^) a0 -< realToFrac dt *^ a++-- | A very crude version of a derivative. It simply divides the value+-- difference by the time difference. Use at your own risk.+derivative :: (Monad m, Fractional s, VectorSpace a s) => SF m a a+derivative = derivativeFrom zeroVector++-- | A very crude version of a derivative. It simply divides the value+-- difference by the time difference. Use at your own risk.+--+-- Starts from a given value for the input signal at time zero.+derivativeFrom :: (Monad m, Fractional s, VectorSpace a s) => a -> SF m a a+derivativeFrom a0 = proc a -> do+  dt   <- constM ask  -< ()+  aOld <- iPre a0     -< a+  returnA             -< (a ^-^ aOld) ^/ realToFrac dt++-- | Integrate using an auxiliary function that takes the current and the last+-- input, the time between those samples, and the last output, and returns a+-- new output.++-- NOTE: BUG in this function, it needs two a's but we can only provide one+iterFrom :: Monad m => (a -> a -> DTime -> b -> b) -> b -> SF m a b+iterFrom f b = MSF $ \a -> do+  dt <- ask+  let b' = f a a dt b+  return (b, iterFrom f b')
+ src/FRP/BearRiver/Time.hs view
@@ -0,0 +1,44 @@+-- |+-- Copyright  : (c) Ivan Perez, 2019-2023+--              (c) Ivan Perez and Manuel Baerenz, 2016-2018+-- License    : BSD3+-- Maintainer : ivan.perez@keera.co.uk+--+-- Maintainer  : ivan.perez@keera.co.uk+-- Stability   : provisional+-- Portability : non-portable (GHC extensions)+--+-- SF primitives that producing the current running time.+--+-- Time is global for an 'SF', so, every constituent 'SF' will use the same+-- global clock. However, when used in combination with+-- 'FRP.BearRiver.Switches.switch'ing, the SF switched into will be started at+-- the time of switching, so any reference to 'localTime' or 'time' from that+-- 'SF' will count using the time of switching as the start time.+--+-- Take also into account that, because 'FRP.BearRiver.Integration.derivative'+-- is the derivative of a signal /over time/, differentiating 'localTime' will+-- always produce the value one (@1@). If you really, really, really need to+-- know the time delta, and need to abandon the hybrid\/FRP abstraction, see+-- 'FRP.BearRiver.Integration.iterFrom'.+module FRP.BearRiver.Time+    ( localTime+    , time+    )+  where++-- External imports+import Control.Arrow ((>>>))++-- Internal imports+import FRP.BearRiver.Basic        (constant)+import FRP.BearRiver.Integration  (integral)+import FRP.BearRiver.InternalCore (SF, Time)++-- | Outputs the time passed since the signal function instance was started.+localTime :: Monad m => SF m a Time+localTime = constant 1.0 >>> integral++-- | Alternative name for localTime.+time :: Monad m => SF m a Time+time = localTime