Copyright | Copyright (c) 2009-2013, David Sorokin <david.sorokin@gmail.com> |
---|---|
License | BSD3 |
Maintainer | David Sorokin <david.sorokin@gmail.com> |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Tested with: GHC 7.8.3
The module defines the Event
monad which is very similar to the Dynamics
monad but only now the computation is strongly synchronized with the event queue.
- data Event a
- class EventLift m where
- data EventProcessing
- runEvent :: Event a -> Dynamics a
- runEventWith :: EventProcessing -> Event a -> Dynamics a
- runEventInStartTime :: Event a -> Simulation a
- runEventInStopTime :: Event a -> Simulation a
- enqueueEvent :: Double -> Event () -> Event ()
- enqueueEventWithCancellation :: Double -> Event () -> Event EventCancellation
- enqueueEventWithTimes :: [Double] -> Event () -> Event ()
- enqueueEventWithIntegTimes :: Event () -> Event ()
- yieldEvent :: Event () -> Event ()
- eventQueueCount :: Event Int
- data EventCancellation
- cancelEvent :: EventCancellation -> Event ()
- eventCancelled :: EventCancellation -> Event Bool
- eventFinished :: EventCancellation -> Event Bool
- catchEvent :: Event a -> (IOException -> Event a) -> Event a
- finallyEvent :: Event a -> Event b -> Event a
- throwEvent :: IOException -> Event a
- memoEvent :: Event a -> Simulation (Event a)
- memoEventInTime :: Event a -> Simulation (Event a)
- newtype DisposableEvent = DisposableEvent {
- disposeEvent :: Event ()
Event Monad
A value in the Event
monad represents a polymorphic time varying function
which is strongly synchronized with the event queue.
data EventProcessing Source
Defines how the events are processed.
CurrentEvents | either process all earlier and then current events,
or raise an error if the current simulation time is less
than the actual time of the event queue (safe within
the |
EarlierEvents | either process all earlier events not affecting
the events at the current simulation time,
or raise an error if the current simulation time is less
than the actual time of the event queue (safe within
the |
CurrentEventsOrFromPast | either process all earlier and then current events, or do nothing if the current simulation time is less than the actual time of the event queue (do not use unless the documentation states the opposite) |
EarlierEventsOrFromPast | either process all earlier events, or do nothing if the current simulation time is less than the actual time of the event queue (do not use unless the documentation states the opposite) |
runEvent :: Event a -> Dynamics a Source
Run the Event
computation in the current simulation time
within the Dynamics
computation involving all pending
CurrentEvents
in the processing too.
runEventWith :: EventProcessing -> Event a -> Dynamics a Source
runEventInStartTime :: Event a -> Simulation a Source
Run the Event
computation in the start time involving all
pending CurrentEvents
in the processing too.
runEventInStopTime :: Event a -> Simulation a Source
Run the Event
computation in the stop time involving all
pending CurrentEvents
in the processing too.
Event Queue
enqueueEvent :: Double -> Event () -> Event () Source
Enqueue the event which must be actuated at the specified time.
The events are processed when calling the runEvent
function. So,
if you want to insist on their immediate execution then you can apply
something like
liftDynamics $ runEvent IncludingCurrentEvents $ return ()
although this is generally not good idea.
enqueueEventWithCancellation :: Double -> Event () -> Event EventCancellation Source
Enqueue the event with an ability to cancel it.
enqueueEventWithTimes :: [Double] -> Event () -> Event () Source
Actuate the event handler in the specified time points.
enqueueEventWithIntegTimes :: Event () -> Event () Source
Actuate the event handler in the integration time points.
yieldEvent :: Event () -> Event () Source
Enqueue the event which must be actuated with the current modeling time but later.
eventQueueCount :: Event Int Source
Return the number of pending events that should be yet actuated.
Cancelling Event
data EventCancellation Source
It allows cancelling the event.
cancelEvent :: EventCancellation -> Event () Source
Cancel the event.
eventCancelled :: EventCancellation -> Event Bool Source
Test whether the event was cancelled.
eventFinished :: EventCancellation -> Event Bool Source
Test whether the event was processed and finished.
Error Handling
catchEvent :: Event a -> (IOException -> Event a) -> Event a Source
Exception handling within Event
computations.
finallyEvent :: Event a -> Event b -> Event a Source
A computation with finalization part like the finally
function.
throwEvent :: IOException -> Event a Source
Like the standard throw
function.
Memoization
memoEvent :: Event a -> Simulation (Event a) Source
Memoize the Event
computation, always returning the same value
within a simulation run.
memoEventInTime :: Event a -> Simulation (Event a) Source
Memoize the Event
computation, always returning the same value
in the same modeling time. After the time changes, the value is
recalculated by demand.
It is possible to implement this function efficiently, for the Event
computation is always synchronized with the event queue which time
flows in one direction only. This synchronization is a key difference
between the Event
and Dynamics
computations.
Disposable
newtype DisposableEvent Source
Defines a computation disposing some entity.
DisposableEvent | |
|