Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell98 |
- data Machine s i = Machine {}
- validate :: Machine s i -> [i] -> Either (s, i) s
- validates :: Machine s i -> [i] -> [Either (s, i) s]
- simulate :: Machine s i -> [i] -> Process (s, i) (s, i)
- data Profile s = Profile {
- profileState :: s
- profileTime :: Timestamp
- profile :: (Ord s, Eq s) => Machine s i -> (i -> Timestamp) -> [i] -> Process (Profile s, i) (s, Timestamp, Timestamp)
- profileIndexed :: (Ord k, Ord s, Eq s) => Machine s i -> (i -> Maybe k) -> (i -> Timestamp) -> [i] -> Process (Map k (Profile s), i) (k, (s, Timestamp, Timestamp))
- profileRouted :: (Ord k, Ord s, Eq s, Eq r) => Machine s i -> Machine r i -> (r -> i -> Maybe k) -> (i -> Timestamp) -> [i] -> Process ((Map k (Profile s), r), i) (k, (s, Timestamp, Timestamp))
- extractIndexed :: Ord k => (s -> i -> Maybe o) -> (i -> Maybe k) -> Map k s -> i -> Maybe (k, o)
- refineM :: (i -> j) -> Machine s j -> Machine s i
- profileM :: Ord s => (i -> Timestamp) -> Machine s i -> Machine (Profile s) i
- indexM :: Ord k => (i -> Maybe k) -> Machine s i -> Machine (Map k s) i
- toList :: Process e a -> [a]
- toMaybe :: Process e a -> Maybe e
- data Process e a
- routeM :: Ord k => Machine r i -> (r -> i -> Maybe k) -> Machine s i -> Machine (Map k s, r) i
Documentation
This is based on a simple finite state machine hence the names delta
for the state transition function.
Since states might be more than simple pattern matched constructors, we
use `finals :: state -> Bool`, rather than `Set state`, to indicate that
the machine is in some final state. Similarly for alpha
, which
indicates the alphabet of inputs to a machine.
The function delta
returns Maybe
values, where Nothing
indicates that no valid transition is possible: ie, there has been an
error.
validate :: Machine s i -> [i] -> Either (s, i) s Source
The validate
function takes a machine and a list of inputs. The machine
is started from its initial state and run against the inputs in turn.
It returns the state and input on failure, and just the state on success.
simulate :: Machine s i -> [i] -> Process (s, i) (s, i) Source
This function produces a process that outputs all the states that a machine goes through.
A state augmented by Timestamp information is held in profileState
.
When the state changes, profileMap
stores a map between each state
and its cumulative time.
Profile | |
|
profileIndexed :: (Ord k, Ord s, Eq s) => Machine s i -> (i -> Maybe k) -> (i -> Timestamp) -> [i] -> Process (Map k (Profile s), i) (k, (s, Timestamp, Timestamp)) Source
profileRouted :: (Ord k, Ord s, Eq s, Eq r) => Machine s i -> Machine r i -> (r -> i -> Maybe k) -> (i -> Timestamp) -> [i] -> Process ((Map k (Profile s), r), i) (k, (s, Timestamp, Timestamp)) Source
extractIndexed :: Ord k => (s -> i -> Maybe o) -> (i -> Maybe k) -> Map k s -> i -> Maybe (k, o) Source
refineM :: (i -> j) -> Machine s j -> Machine s i Source
Machines sometimes need to operate on coarser input than they are defined for. This function takes a function that refines input and a machine that works on refined input, and produces a machine that can work on coarse input.
profileM :: Ord s => (i -> Timestamp) -> Machine s i -> Machine (Profile s) i Source
This function takes a machine and profiles its state.