Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io-sim: generalise selector types #198

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 15 additions & 11 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 @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
Loading