Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize newStates #18

Open
mroman42 opened this issue Jan 8, 2015 · 1 comment
Open

Generalize newStates #18

mroman42 opened this issue Jan 8, 2015 · 1 comment

Comments

@mroman42
Copy link
Member

mroman42 commented Jan 8, 2015

newStates is an auxiliary function for listStates. Its type may be generalizable to:

(Automata a) => a -> State -> [State]

But to generalize its type, we would need to create a function whose particular cases for [] and Maybe were catMaybes and concat, as we can see here (from ToGraph.hs):

listStates :: DFA -> [State]
listStates dfa = stabilize (nub . concat . (map (newStates dfa))) [fromJust (initialDFA dfa)]

newStates :: DFA -> State -> [State]
newStates dfa s = s : catMaybes [(deltaDFA dfa) s a | a <- (alphaDFA dfa)]

listStatesNfa :: NFA -> [State]
listStatesNfa nfa = stabilize (nub . concat . (map (newStatesNfa nfa))) (initialNFA nfa)

newStatesNfa :: NFA -> State -> [State]
newStatesNfa nfa s = s : concat [(deltaNFA nfa) s a | a <- (alphaNFA nfa)]
@mx-psi
Copy link
Contributor

mx-psi commented Jan 8, 2015

I think the simplest solution is using toNFA function to convert the automata given as input to an NFA (or the most general type if we have a more general one) and define

listStates :: (Automata a m) => a -> State -> [State]
listStates = listStatesNfa . toNFA

as the general function. Since Graphviz doesn't care about the type of the automaton, this solution is valid for both types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants