Skip to content

Commit e4ebb82

Browse files
committed
io-sim: generalise selector types
Generalised `selectTraceEvents'` and friends. It can work with any return type, not just `SimResult`.
1 parent 785dc08 commit e4ebb82

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

io-sim/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
the value to other waiting threads.
1515
- Faster handling of timeouts and timers by using a more efficient
1616
internal representation.
17+
- The signature of:
18+
- `selectTraceEvents'`,
19+
- `selectTraceEventsDynamic'`,
20+
- `selectTraceEventsDynamicWithTime'`,
21+
- `selectTraceEventsSay'` and
22+
- `selectTraceEventsSayWithTime'`
23+
is more general. These functions now accepts trace with any result, rather
24+
than one that finishes with `SimResult`.
1725

1826
## 1.6.0.0
1927

io-sim/src/Control/Monad/IOSim.hs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,12 @@ selectTraceEvents fn =
144144
. traceSelectTraceEvents fn
145145

146146
-- | Like 'selectTraceEvents', but it returns even if the simulation trace ends
147-
-- with 'Failure'.
147+
-- with 'Failure'. It also works with any return type, not only `SimResult`
148+
-- like `selectTraceEvents` does.
148149
--
149150
selectTraceEvents'
150151
:: (Time -> SimEventType -> Maybe b)
151-
-> SimTrace a
152+
-> Trace a SimEvent
152153
-> [b]
153154
selectTraceEvents' fn =
154155
bifoldr ( \ _ _ -> [] )
@@ -225,20 +226,22 @@ selectTraceEventsDynamicWithTime = selectTraceEvents fn
225226
fn t (EventLog dyn) = (t,) <$> fromDynamic dyn
226227
fn _ _ = Nothing
227228

228-
-- | Like 'selectTraceEventsDynamic' but it returns even if the simulation trace
229-
-- ends with 'Failure'.
229+
-- | Like 'selectTraceEventsDynamic' but it returns even if the simulation
230+
-- trace ends with 'Failure'. It also works with any return type, not only
231+
-- `SimResult` like `selectTraceEventsDynamic` does.
230232
--
231-
selectTraceEventsDynamic' :: forall a b. Typeable b => SimTrace a -> [b]
233+
selectTraceEventsDynamic' :: forall a b. Typeable b => Trace a SimEvent -> [b]
232234
selectTraceEventsDynamic' = selectTraceEvents' fn
233235
where
234236
fn :: Time -> SimEventType -> Maybe b
235237
fn _ (EventLog dyn) = fromDynamic dyn
236238
fn _ _ = Nothing
237239

238-
-- | Like `selectTraceEventsDynamic'` but it also captures time of the trace
239-
-- event.
240+
-- | Like `selectTraceEventsDynamicWithTime'` but it also captures time of the
241+
-- trace event. It also works with any return type, not only `SimResult` like
242+
-- `selectTraceEventsDynamicWithTime` does.
240243
--
241-
selectTraceEventsDynamicWithTime' :: forall a b. Typeable b => SimTrace a -> [(Time, b)]
244+
selectTraceEventsDynamicWithTime' :: forall a b. Typeable b => Trace a SimEvent -> [(Time, b)]
242245
selectTraceEventsDynamicWithTime' = selectTraceEvents' fn
243246
where
244247
fn :: Time -> SimEventType -> Maybe (Time, b)
@@ -266,9 +269,10 @@ selectTraceEventsSayWithTime = selectTraceEvents fn
266269
fn _ _ = Nothing
267270

268271
-- | Like 'selectTraceEventsSay' but it returns even if the simulation trace
269-
-- ends with 'Failure'.
272+
-- ends with 'Failure'. It also works with any return type, not only `SimResult`
273+
-- like `selectTraceEventsSay` does.
270274
--
271-
selectTraceEventsSay' :: SimTrace a -> [String]
275+
selectTraceEventsSay' :: Trace a SimEvent -> [String]
272276
selectTraceEventsSay' = selectTraceEvents' fn
273277
where
274278
fn :: Time -> SimEventType -> Maybe String
@@ -277,7 +281,7 @@ selectTraceEventsSay' = selectTraceEvents' fn
277281

278282
-- | Like `selectTraceEventsSay'` but it also captures time of the trace event.
279283
--
280-
selectTraceEventsSayWithTime' :: SimTrace a -> [(Time, String)]
284+
selectTraceEventsSayWithTime' :: Trace a SimEvent -> [(Time, String)]
281285
selectTraceEventsSayWithTime' = selectTraceEvents' fn
282286
where
283287
fn :: Time -> SimEventType -> Maybe (Time, String)

0 commit comments

Comments
 (0)