Advertisement
Guest User

automata

a guest
Sep 23rd, 2010
1,067
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Prelude hiding (init)    -- so we can use the name 'init' later
  2.  
  3. type Automaton a = [a] -> Bool
  4. type AutomatonPair a = (a, Automaton a)
  5.  
  6. accept :: Eq a => [AutomatonPair a] -> Automaton a
  7. accept ps = f
  8.   where f [] = True
  9.         f (x:xs) = case lookup x ps of
  10.           Just a -> a xs
  11.           Nothing -> False
  12.  
  13. v s@('c':_) = init s
  14.   where init = accept [('c', loop)]
  15.         loop = accept [('a', loop),
  16.                        ('d', loop),
  17.                        ('r', end)]
  18.         end = accept [('r', end)]
  19. v s = see0 s
  20.   where see0 = accept [('0', see1)]
  21.         see1 = accept [('1', see0)]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement