Skip to content

Commit 33e1d8c

Browse files
Merge branch 'release-0.11.2'. Refs #377.
2 parents 124fcba + 20c69b3 commit 33e1d8c

File tree

11 files changed

+383
-86
lines changed

11 files changed

+383
-86
lines changed

dunai-frp-bearriver/CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2023-08-21 Ivan Perez <ivan.perez@keera.co.uk>
2+
* Version bump (0.14.4) (#377).
3+
* Offer all definitions from FRP.Yampa.Basic (#376).
4+
15
2023-06-21 Ivan Perez <ivan.perez@keera.co.uk>
26
* Version bump (0.14.3) (#372).
37
* Offer all definitions from FRP.Yampa.Arrow (#360).

dunai-frp-bearriver/bearriver.cabal

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ cabal-version: >= 1.10
3030
build-type: Simple
3131

3232
name: bearriver
33-
version: 0.14.3
33+
version: 0.14.4
3434
author: Ivan Perez, Manuel Bärenz
3535
maintainer: ivan.perez@keera.co.uk
3636
homepage: https://github.com/ivanperez-keera/dunai
@@ -77,8 +77,12 @@ library
7777
exposed-modules:
7878
FRP.BearRiver
7979
FRP.BearRiver.Arrow
80+
FRP.BearRiver.Basic
8081
FRP.Yampa
8182

83+
other-modules:
84+
FRP.BearRiver.InternalCore
85+
8286
build-depends:
8387
base >= 4.6 && <5
8488
, deepseq >= 1.3.0.0 && < 1.5

dunai-frp-bearriver/src/FRP/BearRiver.hs

Lines changed: 3 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import Control.Applicative (Applicative (..), (<$>))
2626
#endif
2727
import Control.Applicative (Alternative (..))
2828
import Control.Arrow as X
29-
import qualified Control.Category as Category
3029
import Control.DeepSeq (NFData (..))
3130
import qualified Control.Monad.Fail as Fail
3231
import Control.Monad.Random (MonadRandom)
@@ -47,36 +46,16 @@ import Data.MonadicStreamFunction as X hiding
4746
trace)
4847
import Data.MonadicStreamFunction.InternalCore (MSF (MSF, unMSF))
4948
import FRP.BearRiver.Arrow as X
49+
import FRP.BearRiver.Basic as X
50+
import FRP.BearRiver.InternalCore as X
5051

5152
-- Internal imports (dunai, instances)
5253
import Data.MonadicStreamFunction.Instances.ArrowLoop () -- not needed, just
5354
-- re-exported
54-
55-
infixr 0 -->, -:>, >--, >=-
55+
--
5656

5757
-- * Basic definitions
5858

59-
-- | Time is used both for time intervals (duration), and time w.r.t. some
60-
-- agreed reference point in time.
61-
type Time = Double
62-
63-
-- | DTime is the time type for lengths of sample intervals. Conceptually,
64-
-- DTime = R+ = { x in R | x > 0 }. Don't assume Time and DTime have the same
65-
-- representation.
66-
type DTime = Double
67-
68-
-- | Extensible signal function (signal function with a notion of time, but
69-
-- which can be extended with actions).
70-
--
71-
-- Signal function that transforms a signal carrying values of some type 'a'
72-
-- into a signal carrying values of some type 'b'. You can think of it as
73-
-- (Signal a -> Signal b). A signal is, conceptually, a function from 'Time' to
74-
-- value.
75-
type SF m = MSF (ClockInfo m)
76-
77-
-- | Information on the progress of time.
78-
type ClockInfo m = ReaderT DTime m
79-
8059
-- | A single possible event occurrence, that is, a value that may or may not
8160
-- occur. Events are used to represent values that are not produced
8261
-- continuously, such as mouse clicks (only produced when the mouse is clicked,
@@ -144,22 +123,6 @@ arrEPrim = arr
144123

145124
-- ** Basic signal functions
146125

147-
-- | Identity: identity = arr id
148-
--
149-
-- Using 'identity' is preferred over lifting id, since the arrow combinators
150-
-- know how to optimise certain networks based on the transformations being
151-
-- applied.
152-
identity :: Monad m => SF m a a
153-
identity = Category.id
154-
155-
-- | Identity: constant b = arr (const b)
156-
--
157-
-- Using 'constant' is preferred over lifting const, since the arrow
158-
-- combinators know how to optimise certain networks based on the
159-
-- transformations being applied.
160-
constant :: Monad m => b -> SF m a b
161-
constant = arr . const
162-
163126
-- | Outputs the time passed since the signal function instance was started.
164127
localTime :: Monad m => SF m a Time
165128
localTime = constant 1.0 >>> integral
@@ -168,40 +131,6 @@ localTime = constant 1.0 >>> integral
168131
time :: Monad m => SF m a Time
169132
time = localTime
170133

171-
-- ** Initialization
172-
173-
-- | Initialization operator (cf. Lustre/Lucid Synchrone).
174-
--
175-
-- The output at time zero is the first argument, and from that point on it
176-
-- behaves like the signal function passed as second argument.
177-
(-->) :: Monad m => b -> SF m a b -> SF m a b
178-
b0 --> sf = sf >>> replaceOnce b0
179-
180-
-- | Output pre-insert operator.
181-
--
182-
-- Insert a sample in the output, and from that point on, behave like the given
183-
-- sf.
184-
(-:>) :: Monad m => b -> SF m a b -> SF m a b
185-
b -:> sf = iPost b sf
186-
187-
-- | Input initialization operator.
188-
--
189-
-- The input at time zero is the first argument, and from that point on it
190-
-- behaves like the signal function passed as second argument.
191-
(>--) :: Monad m => a -> SF m a b -> SF m a b
192-
a0 >-- sf = replaceOnce a0 >>> sf
193-
194-
-- | Transform initial input value.
195-
--
196-
-- Applies a transformation 'f' only to the first input value at time zero.
197-
(>=-) :: Monad m => (a -> a) -> SF m a b -> SF m a b
198-
f >=- sf = MSF $ \a -> do
199-
(b, sf') <- unMSF sf (f a)
200-
return (b, sf')
201-
202-
-- | Override initial value of input signal.
203-
initially :: Monad m => a -> SF m a a
204-
initially = (--> identity)
205134

206135
-- * Simple, stateful signal processing
207136

@@ -878,12 +807,3 @@ evalAt sf dt a = runIdentity $ runReaderT (unMSF sf a) dt
878807
-- discrete and step based.
879808
evalFuture :: SF Identity a b -> a -> DTime -> (b, SF Identity a b)
880809
evalFuture sf = flip (evalAt sf)
881-
882-
-- * Auxiliary functions
883-
884-
-- ** Event handling
885-
886-
-- | Replace the value of the input signal at time zero with the given
887-
-- argument.
888-
replaceOnce :: Monad m => a -> SF m a a
889-
replaceOnce a = dSwitch (arr $ const (a, Event ())) (const $ arr id)
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
-- |
2+
-- Module : FRP.BearRiver.Basic
3+
-- Copyright : (c) Ivan Perez, 2014-2022
4+
-- (c) George Giorgidze, 2007-2012
5+
-- (c) Henrik Nilsson, 2005-2006
6+
-- (c) Antony Courtney and Henrik Nilsson, Yale University, 2003-2004
7+
-- License : BSD-style (see the LICENSE file in the distribution)
8+
--
9+
-- Maintainer : ivan.perez@keera.co.uk
10+
-- Stability : provisional
11+
-- Portability : non-portable (GHC extensions)
12+
--
13+
-- Defines basic signal functions, and elementary ways of altering them.
14+
--
15+
-- This module defines very basic ways of creating and modifying signal
16+
-- functions. In particular, it defines ways of creating constant output
17+
-- producing SFs, and SFs that just pass the signal through unmodified.
18+
--
19+
-- It also defines ways of altering the input and the output signal only by
20+
-- inserting one value in the signal, or by transforming it.
21+
module FRP.BearRiver.Basic
22+
(
23+
-- * Basic signal functions
24+
identity
25+
, constant
26+
27+
-- ** Initialization
28+
, (-->)
29+
, (-:>)
30+
, (>--)
31+
, (-=>)
32+
, (>=-)
33+
, initially
34+
)
35+
where
36+
37+
-- External imports
38+
import qualified Control.Category as Category
39+
40+
-- Internal imports (dunai)
41+
import Data.MonadicStreamFunction.InternalCore (MSF (MSF, unMSF))
42+
43+
-- Internal imports
44+
import FRP.BearRiver.InternalCore (SF, arr)
45+
46+
infixr 0 -->, -:>, >--, -=>, >=-
47+
48+
-- * Basic signal functions
49+
50+
-- | Identity: identity = arr id
51+
--
52+
-- Using 'identity' is preferred over lifting id, since the arrow combinators
53+
-- know how to optimise certain networks based on the transformations being
54+
-- applied.
55+
identity :: Monad m => SF m a a
56+
identity = Category.id
57+
58+
-- | Identity: constant b = arr (const b)
59+
--
60+
-- Using 'constant' is preferred over lifting const, since the arrow combinators
61+
-- know how to optimise certain networks based on the transformations being
62+
-- applied.
63+
constant :: Monad m => b -> SF m a b
64+
constant = arr . const
65+
66+
-- * Initialization
67+
68+
-- | Initialization operator (cf. Lustre/Lucid Synchrone).
69+
--
70+
-- The output at time zero is the first argument, and from that point on it
71+
-- behaves like the signal function passed as second argument.
72+
(-->) :: Monad m => b -> SF m a b -> SF m a b
73+
b0 --> sf = MSF $ \a -> do
74+
(_b, sf') <- unMSF sf a
75+
return (b0, sf')
76+
77+
-- | Output pre-insert operator.
78+
--
79+
-- Insert a sample in the output, and from that point on, behave like the given
80+
-- sf.
81+
(-:>) :: Monad m => b -> SF m a b -> SF m a b
82+
b -:> sf = MSF $ \_a -> return (b, sf)
83+
84+
-- | Input initialization operator.
85+
--
86+
-- The input at time zero is the first argument, and from that point on it
87+
-- behaves like the signal function passed as second argument.
88+
(>--) :: Monad m => a -> SF m a b -> SF m a b
89+
a0 >-- sf = MSF $ \_ -> unMSF sf a0
90+
91+
-- | Transform initial output value.
92+
--
93+
-- Applies a transformation 'f' only to the first output value at time zero.
94+
(-=>) :: Monad m => (b -> b) -> SF m a b -> SF m a b
95+
f -=> sf = MSF $ \a -> do
96+
(b, sf') <- unMSF sf a
97+
return (f b, sf')
98+
99+
-- | Transform initial input value.
100+
--
101+
-- Applies a transformation 'f' only to the first input value at time zero.
102+
(>=-) :: Monad m => (a -> a) -> SF m a b -> SF m a b
103+
f >=- sf = MSF $ \a -> do
104+
(b, sf') <- unMSF sf (f a)
105+
return (b, sf')
106+
107+
-- | Override initial value of input signal.
108+
initially :: Monad m => a -> SF m a a
109+
initially = (--> identity)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
-- |
2+
-- Module : FRP.Dunai.InternalCore
3+
-- Copyright : (c) Ivan Perez, 2014-2022
4+
-- (c) George Giorgidze, 2007-2012
5+
-- (c) Henrik Nilsson, 2005-2006
6+
-- (c) Antony Courtney and Henrik Nilsson, Yale University, 2003-2004
7+
-- License : BSD-style (see the LICENSE file in the distribution)
8+
--
9+
-- Maintainer : ivan.perez@keera.co.uk
10+
-- Stability : provisional
11+
-- Portability : non-portable (GHC extensions)
12+
--
13+
-- Domain-specific language embedded in Haskell for programming hybrid (mixed
14+
-- discrete-time and continuous-time) systems, extended with Monads.
15+
--
16+
-- Bearriver (a tributary to the Yampa river) provides the same API as Yampa,
17+
-- but implemented using Monadic Stream Functions underneath. SFs in BearRiver
18+
-- take an additional monad as argument. The introduction of time is done by
19+
-- means of an additional Reader layer.
20+
module FRP.BearRiver.InternalCore
21+
( module Control.Arrow
22+
23+
-- * Basic definitions
24+
-- ** Time
25+
, Time
26+
, DTime
27+
28+
-- ** Signal Functions
29+
, SF
30+
, ClockInfo
31+
)
32+
where
33+
34+
-- External imports
35+
import Control.Arrow (Arrow (..), ArrowChoice (..), ArrowLoop (..), (>>>))
36+
37+
-- Internal imports (dunai)
38+
import Control.Monad.Trans.MSF (ReaderT)
39+
import Data.MonadicStreamFunction (MSF)
40+
41+
-- * Basic type definitions with associated utilities
42+
43+
-- | Time is used both for time intervals (duration), and time w.r.t. some
44+
-- agreed reference point in time.
45+
type Time = Double
46+
47+
-- | DTime is the time type for lengths of sample intervals. Conceptually,
48+
-- DTime = R+ = { x in R | x > 0 }. Don't assume Time and DTime have the same
49+
-- representation.
50+
type DTime = Double
51+
52+
-- | Extensible signal function (signal function with a notion of time, but
53+
-- which can be extended with actions).
54+
--
55+
-- Signal function that transforms a signal carrying values of some type 'a'
56+
-- into a signal carrying values of some type 'b'. You can think of it as
57+
-- (Signal a -> Signal b). A signal is, conceptually, a function from 'Time' to
58+
-- value.
59+
type SF m = MSF (ClockInfo m)
60+
61+
-- | Information on the progress of time.
62+
type ClockInfo m = ReaderT DTime m

dunai-test/CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2023-08-21 Ivan Perez <ivan.perez@keera.co.uk>
2+
* Version bump (0.11.2) (#377).
3+
14
2023-06-21 Ivan Perez <ivan.perez@keera.co.uk>
25
* Version bump (0.11.1) (#372).
36

dunai-test/dunai-test.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ cabal-version: >= 1.10
3030
build-type: Simple
3131

3232
name: dunai-test
33-
version: 0.11.1
33+
version: 0.11.2
3434
author: Ivan Perez
3535
maintainer: ivan.perez@keera.co.uk
3636
homepage: https://github.com/ivanperez-keera/dunai

dunai/CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2023-08-21 Ivan Perez <ivan.perez@keera.co.uk>
2+
* Version bump (0.11.2) (#377).
3+
* Introduce benchmark (#375).
4+
15
2023-06-21 Ivan Perez <ivan.perez@keera.co.uk>
26
* Version bump (0.11.1) (#372).
37
* Reflect new contribution process in README (#362).

dunai/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ game, but we need to run newer reliable benchmarks including every module and
349349
only definitions from `FRP.Yampa`, `FRP.BearRiver` and
350350
`Data.MonadicStreamFunction`.
351351

352+
Dunai includes some benchmarks as part of the main library. You are encouraged
353+
to use them to evaluate your pull requests, and to improve the benchmarks
354+
themselves.
355+
352356
# Contributions
353357
<sup>[(Back to top)](#table-of-contents)</sup>
354358

@@ -410,6 +414,10 @@ This project is split in three parts:
410414
- _Examples_: ballbounce
411415
- sample applications that work both on traditional Yampa and BearRiver.
412416

417+
Dunai also includes some benchmarks as part of the main library. You are
418+
encouraged to use them to evaluate your pull requests, and to improve the
419+
benchmarks themselves.
420+
413421
## Style
414422
<sup>[(Back to top)](#table-of-contents)</sup>
415423

0 commit comments

Comments
 (0)