Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Considerations
One caveat you should always take into account when using this package is that without some data creation from the user, the use of this package is a bit restricted. This happens because the way it is built the package forbids you to use more than one type of information between states (or inside one), so to work around this, if you want to have multiple types of information inside states, do as follows:
data myCustomData = Type1 String | Type2 Int deriving (Show,Eq)
dont forget about the deriving because otherwise it will conflict with the functions in the package.
Synopsis
- type State = Int
- type Tag = String
- data StateInfo a
- data AutomataInfo a
- createStateInfo :: State -> Tag -> a -> AutomataInfo a
- fromlsStateInfo :: Eq a => State -> [(Tag, a)] -> Maybe (AutomataInfo a) -> AutomataInfo a
- getStateInfo :: StateInfo a -> Map Tag a
- getStatesWithInfo :: AutomataInfo a -> [State]
- getTagsInState :: AutomataInfo a -> State -> [Tag]
- getInfoInState :: AutomataInfo a -> State -> Maybe Tag -> StateInfo a
- alterStateInfo :: State -> Maybe Tag -> a -> AutomataInfo a -> AutomataInfo a
- unionStateInfo :: AutomataInfo a -> AutomataInfo a -> AutomataInfo a
Documentation
data AutomataInfo a Source #
Instances
Eq a => Eq (AutomataInfo a) Source # | |
Defined in FSM.States (==) :: AutomataInfo a -> AutomataInfo a -> Bool # (/=) :: AutomataInfo a -> AutomataInfo a -> Bool # | |
Show a => Show (AutomataInfo a) Source # | |
Defined in FSM.States showsPrec :: Int -> AutomataInfo a -> ShowS # show :: AutomataInfo a -> String # showList :: [AutomataInfo a] -> ShowS # |
Creating functions
createStateInfo :: State -> Tag -> a -> AutomataInfo a Source #
This function takes a State, a Tag and a value and creates an AutomataInfo object containing only the given State with the value and the tag associated to it. E.g.:
createStateInfo 4 "tag" 25
If you created your own data type, you can do as follows:
my_info = createStateInfo 4 "tag" (Type2 Int)
fromlsStateInfo :: Eq a => State -> [(Tag, a)] -> Maybe (AutomataInfo a) -> AutomataInfo a Source #
This function takes a State, a list of (Tag,value) and Maybe AutomataInfo and returns the AutomataInfo updated with the list of tags given. Please notice that if Nothing is given, it will return the created AutomataInfo while if a (Just AutomataInfo) object is given, it will update the tags in the given state.
E.g. (notice that we are using my_info
from the previous example)
fromlsStateInfo 4 [("foo", Type1 "on"),("bar", Type2 0)] Nothing fromlsStateInfo 4 [("foo", Type1 "on"),("bar", Type2 0)] (Just my_info)
Accessing functions
getStatesWithInfo :: AutomataInfo a -> [State] Source #
This function returns the states of the given AutomataInfo that currently contain some information
getTagsInState :: AutomataInfo a -> State -> [Tag] Source #
This function returns the tags that a given state contains inside the AutomataInfo
getInfoInState :: AutomataInfo a -> State -> Maybe Tag -> StateInfo a Source #
This function returns the information contained in the given state. If Nothing
is given, then it returns all the information in the state while if Just tag
is given, it will return only the information inside the given tag.
E.g:
getInfoInState my_info 4 Nothing getInfoInState my_info 4 (Just "foo")
Editing functions
alterStateInfo :: State -> Maybe Tag -> a -> AutomataInfo a -> AutomataInfo a Source #
This function takes a State, Maybe Tag, a value and an AutomataInfo object and updates the value of the Tag in the given State. Please note that if if Nothing is given, it will delete the State. E.g:
alterStateInfo 3 (Just "foo") (Type2 45) my_info
unionStateInfo :: AutomataInfo a -> AutomataInfo a -> AutomataInfo a Source #
This function takes the left-biased union of t1 and t2. It prefers t1 when duplicate keys are encountered. Works similarly to Data.Map.union.