You use pattern matching for that:
advance :: DA -> State -> String -> State
advance (start, step, accept) fromState chars = ....
The type
keyword just introduces type synonyms. DA
is just a synonym for a triple (Integer, Integer -> Char -> Integer, Integer -> Bool)
.
Your naming is confusing. delta
in the definition of a
automaton is a state transition function, but in the definition of toDA
function, a parameter named delta
is a list. ListDA
type is also just a synonym for a triple (a different one - of a state, a list of transitions, and a list of acceptable states).
Here is how this can be coded, using recursion for loops:
advance (_, step, _) fromState chars = go fromState chars
where
go s [] = ... -- stop, and produce the state as the answer,
-- when the input string (list of chars) has ended
go s (c:cs) = -- if not, then
let s2 = step s c -- make one step
in go ....... -- and loop with new values
Notice we have no need here for the start
or accept
variables, so we can use the anonymous variable pattern _
there. Also, step
is a function of type State -> Char -> State
, and that dictates the order of arguments used in the function call there. I.e. it accepts a state and a character, and produces a new state.
If you don't know Haskell at all, you will likely benefit from reading (and working through) a good tutorial, like this one.
Lastly, since you've said you're "not familiar with posting questions in a forum", please read about accepting answers, and FAQ in general.