From e5fa0dadc553cfedf8c1d0fb71fb9f7b4e5285b3 Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Mon, 9 Dec 2024 11:06:29 +0100 Subject: [PATCH 1/2] io-sim: generalise selector types Generalised `selectTraceEvents'` and friends. It can work with any return type, not just `SimResult`. --- io-sim/CHANGELOG.md | 11 +++++++++++ io-sim/src/Control/Monad/IOSim.hs | 26 +++++++++++++++----------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/io-sim/CHANGELOG.md b/io-sim/CHANGELOG.md index ecfdbc34..60757341 100644 --- a/io-sim/CHANGELOG.md +++ b/io-sim/CHANGELOG.md @@ -1,5 +1,16 @@ # Revision history of io-sim +## 1.5.1.0 + +- The signature of: + - `selectTraceEvents'`, + - `selectTraceEventsDynamic'`, + - `selectTraceEventsDynamicWithTime'`, + - `selectTraceEventsSay'` and + - `selectTraceEventsSayWithTime'` + is more general. These functions now accepts trace with any result, rather + than one that finishes with `SimResult`. + ## 1.5.0.0 ### Breaking changes diff --git a/io-sim/src/Control/Monad/IOSim.hs b/io-sim/src/Control/Monad/IOSim.hs index 565e406c..907e4f27 100644 --- a/io-sim/src/Control/Monad/IOSim.hs +++ b/io-sim/src/Control/Monad/IOSim.hs @@ -144,11 +144,12 @@ selectTraceEvents fn = . traceSelectTraceEvents fn -- | Like 'selectTraceEvents', but it returns even if the simulation trace ends --- with 'Failure'. +-- with 'Failure'. It also works with any return type, not only `SimResult` +-- like `selectTraceEvents` does. -- selectTraceEvents' :: (Time -> SimEventType -> Maybe b) - -> SimTrace a + -> Trace a SimEvent -> [b] selectTraceEvents' fn = bifoldr ( \ _ _ -> [] ) @@ -225,20 +226,22 @@ selectTraceEventsDynamicWithTime = selectTraceEvents fn fn t (EventLog dyn) = (t,) <$> fromDynamic dyn fn _ _ = Nothing --- | Like 'selectTraceEventsDynamic' but it returns even if the simulation trace --- ends with 'Failure'. +-- | Like 'selectTraceEventsDynamic' but it returns even if the simulation +-- trace ends with 'Failure'. It also works with any return type, not only +-- `SimResult` like `selectTraceEventsDynamic` does. -- -selectTraceEventsDynamic' :: forall a b. Typeable b => SimTrace a -> [b] +selectTraceEventsDynamic' :: forall a b. Typeable b => Trace a SimEvent -> [b] selectTraceEventsDynamic' = selectTraceEvents' fn where fn :: Time -> SimEventType -> Maybe b fn _ (EventLog dyn) = fromDynamic dyn fn _ _ = Nothing --- | Like `selectTraceEventsDynamic'` but it also captures time of the trace --- event. +-- | Like `selectTraceEventsDynamicWithTime'` but it also captures time of the +-- trace event. It also works with any return type, not only `SimResult` like +-- `selectTraceEventsDynamicWithTime` does. -- -selectTraceEventsDynamicWithTime' :: forall a b. Typeable b => SimTrace a -> [(Time, b)] +selectTraceEventsDynamicWithTime' :: forall a b. Typeable b => Trace a SimEvent -> [(Time, b)] selectTraceEventsDynamicWithTime' = selectTraceEvents' fn where fn :: Time -> SimEventType -> Maybe (Time, b) @@ -266,9 +269,10 @@ selectTraceEventsSayWithTime = selectTraceEvents fn fn _ _ = Nothing -- | Like 'selectTraceEventsSay' but it returns even if the simulation trace --- ends with 'Failure'. +-- ends with 'Failure'. It also works with any return type, not only `SimResult` +-- like `selectTraceEventsSay` does. -- -selectTraceEventsSay' :: SimTrace a -> [String] +selectTraceEventsSay' :: Trace a SimEvent -> [String] selectTraceEventsSay' = selectTraceEvents' fn where fn :: Time -> SimEventType -> Maybe String @@ -277,7 +281,7 @@ selectTraceEventsSay' = selectTraceEvents' fn -- | Like `selectTraceEventsSay'` but it also captures time of the trace event. -- -selectTraceEventsSayWithTime' :: SimTrace a -> [(Time, String)] +selectTraceEventsSayWithTime' :: Trace a SimEvent -> [(Time, String)] selectTraceEventsSayWithTime' = selectTraceEvents' fn where fn :: Time -> SimEventType -> Maybe (Time, String) From 586ddf6b52be1bbc78f9c659907f8e3fa13ccffe Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Tue, 10 Dec 2024 09:41:04 +0100 Subject: [PATCH 2/2] io-sim-1.5.1.0 --- io-sim/io-sim.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/io-sim/io-sim.cabal b/io-sim/io-sim.cabal index 660a369b..213bfa5e 100644 --- a/io-sim/io-sim.cabal +++ b/io-sim/io-sim.cabal @@ -1,6 +1,6 @@ cabal-version: 3.0 name: io-sim -version: 1.5.0.0 +version: 1.5.1.0 synopsis: A pure simulator for monadic concurrency with STM. description: A pure simulator monad with support of concurency (base & async style), stm,