I am student and in my programming course we have to learn Haskell. So I am new to it and i don't have that much experience. Also I am not familiar with posting questions in a forum.
So first of all I will post the library, I have to work with. (DA : Deterministic Automaton)
type State = Integer
type DA = (State, State -> Char -> State, State -> Bool)
type ListDA = (State, [((State, Char), State)], [State])
a :: DA
a = (0, delta, (==1))
where
delta 0 'a' = 1
delta 1 'a' = 1
delta 2 'a' = 1
delta 0 'b' = 2
delta 1 'b' = 2
delta 2 'b' = 2
toDA :: ListDA -> DA
toDA (start, delta, final) = (start, deltaFun delta, (`elem` final))
where deltaFun dl = curry (fromMaybe 0 . flip lookup dl)
The toDA function takes an automaton in its list representation and converts it into an automaton. This function and the rest of the library is given by the chair of the lecture.
The problem is now to write a function of type
advance :: DA -> State -> String -> State
This function takes an automaton, a state and a String and returns the state of the automaton after reading the String.
The Idea is clear so far. An automaton of type DA has got a state-transition-function delta. So the function "advance" has to call that delta function in some way. But how can I access a function, that is integrated in a type?
`advance :: DA -> State -> String -> State` `advance (start, step, final) state [] = state` `advance (start, step, final) state (char:chars) = advance (start, step, final) (step state char) chars` is it possible to write (start, step, final) just once by using a 'where' statement and replacing the other triples by somethingt like 'Automaton' ? – 0niveau Nov 20 '12 at 19:54