Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

automata

By: a guest on Sep 23rd, 2010  |  syntax: Haskell  |  size: 0.61 KB  |  hits: 635  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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)]