FSM-0.0.4.0: Basic concepts of finite state machines.
Safe HaskellSafe
LanguageHaskell2010

FSM.States

Description

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

Documentation

type State = Int Source #

data StateInfo a Source #

Instances

Instances details
Eq a => Eq (StateInfo a) Source # 
Instance details

Defined in FSM.States

Methods

(==) :: StateInfo a -> StateInfo a -> Bool #

(/=) :: StateInfo a -> StateInfo a -> Bool #

Show a => Show (StateInfo a) Source # 
Instance details

Defined in FSM.States

data AutomataInfo a Source #

Instances

Instances details
Eq a => Eq (AutomataInfo a) Source # 
Instance details

Defined in FSM.States

Show a => Show (AutomataInfo a) Source # 
Instance details

Defined in FSM.States

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.