Data.FsmActions
Contents
Description
Finite state machines.
Here an FSM is a map from symbols to actions. Symbols are parametric
(will usually be Strings or Chars). Actions specify the action of a
symbol on each state, and are represented as lists of transitions: one
per state. States are just numbers, from 0 to n, corresponding to
indices on transition lists in Actions. Then deterministic actions
are just Ints, identifying the state to transition to under that
action; nondeterministic actions are lists of Ints: all the states to
possibly transition to under that action.
- type State = Int
- newtype DestinationSet = DestinationSet {
- destinations :: [State]
- newtype Action = Action {}
- newtype FSM sy = FSM {}
- newtype Word sy = Word [sy]
- states :: FSM sy -> [State]
- alphabet :: FSM sy -> [sy]
- fsmAction :: Ord sy => sy -> FSM sy -> Maybe Action
- data WellFormed sy
- = WellFormed [sy]
- | BadLengths [(sy, Int)]
- | BadActions [(sy, Action)]
- isWellFormed :: Ord sy => FSM sy -> WellFormed sy
- normalise :: FSM sy -> FSM sy
- normaliseAction :: Action -> Action
- mkAction :: [[State]] -> Action
- mkDAction :: [State] -> Action
- append :: Action -> Action -> Action
- actionLookup :: Action -> State -> DestinationSet
- action :: Ord sy => FSM sy -> Word sy -> Maybe Action
- actionEquiv :: Ord sy => FSM sy -> Word sy -> Word sy -> Bool
- destinationSet :: Ord sy => FSM sy -> State -> Word sy -> Maybe DestinationSet
- destinationEquiv :: Ord sy => FSM sy -> State -> Word sy -> Word sy -> Bool
- fsmIdentity :: FSM sy -> Action
- isDAction :: Action -> Bool
- isDFSM :: FSM sy -> Bool
Data types
newtype DestinationSet Source
Destination sets are just lists of States.
Constructors
| DestinationSet | |
Fields
| |
Instances
Finite state machine whose nodes are labelled with type sy.
Simple FSM operations
states :: FSM sy -> [State]Source
Compute the list of states of the FSM. Only really meaningful
if the FSM's well-formedness is not BadLengths. With current
implementation, is just [0..n] for some n (or empty).
Well-formedness
data WellFormed sy Source
An FSM is well-formed if all its actions are the same length,
and none of its actions contain destinations which are out of
range.
Constructors
| WellFormed [sy] |
|
| BadLengths [(sy, Int)] | Lengths of Actions in the |
| BadActions [(sy, Action)] | Some |
Instances
| Eq sy => Eq (WellFormed sy) | |
| Show sy => Show (WellFormed sy) |
isWellFormed :: Ord sy => FSM sy -> WellFormed sySource
Check if an FSM is well-formed or not.
Normalisation
Operations on actions
mkDAction :: [State] -> ActionSource
Build a deterministic action given a list of destination states.
actionLookup :: Action -> State -> DestinationSetSource
Compute the DestinationSet reached by following some Action
from some State.
actionEquiv :: Ord sy => FSM sy -> Word sy -> Word sy -> BoolSource
Test if two Words are action-equivalent over some FSM.
Destination sets
destinationSet :: Ord sy => FSM sy -> State -> Word sy -> Maybe DestinationSetSource
Compute the DestinationSet for some Word at some State of
an FSM. The word might contain symbols outside the FSM's
alphabet, or the state might be out of range, so the result could
be Nothing.
Identity
fsmIdentity :: FSM sy -> ActionSource
Compute the identity action for a given FSM.