Skip to content

Commit

Permalink
io-sim: generalise selector types
Browse files Browse the repository at this point in the history
Generalised `selectTraceEvents'` and friends.  It can work with any
return type, not just `SimResult`.
  • Loading branch information
coot committed Dec 9, 2024
1 parent 785dc08 commit 21392e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 8 additions & 0 deletions io-sim/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
the value to other waiting threads.
- Faster handling of timeouts and timers by using a more efficient
internal representation.
- 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.6.0.0

Expand Down
13 changes: 7 additions & 6 deletions io-sim/src/Control/Monad/IOSim.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ( \ _ _ -> [] )
Expand Down Expand Up @@ -228,7 +229,7 @@ selectTraceEventsDynamicWithTime = selectTraceEvents fn
-- | Like 'selectTraceEventsDynamic' but it returns even if the simulation trace
-- ends with 'Failure'.
--
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
Expand All @@ -238,7 +239,7 @@ selectTraceEventsDynamic' = selectTraceEvents' fn
-- | Like `selectTraceEventsDynamic'` but it also captures time of the trace
-- event.
--
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)
Expand Down Expand Up @@ -268,7 +269,7 @@ selectTraceEventsSayWithTime = selectTraceEvents fn
-- | Like 'selectTraceEventsSay' but it returns even if the simulation trace
-- ends with 'Failure'.
--
selectTraceEventsSay' :: SimTrace a -> [String]
selectTraceEventsSay' :: Trace a SimEvent -> [String]
selectTraceEventsSay' = selectTraceEvents' fn
where
fn :: Time -> SimEventType -> Maybe String
Expand All @@ -277,7 +278,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)
Expand Down

0 comments on commit 21392e6

Please sign in to comment.