import Prelude hiding (init) -- so we can use the name 'init' later type Automaton a = [a] -> Bool type AutomatonPair a = (a, Automaton a) accept :: Eq a => [AutomatonPair a] -> Automaton a accept ps = f where f [] = True f (x:xs) = case lookup x ps of Just a -> a xs Nothing -> False v s@('c':_) = init s where init = accept [('c', loop)] loop = accept [('a', loop), ('d', loop), ('r', end)] end = accept [('r', end)] v s = see0 s where see0 = accept [('0', see1)] see1 = accept [('1', see0)]