Skip to content

Instantly share code, notes, and snippets.

@shhyou
Created March 20, 2013 14:53
Show Gist options
  • Save shhyou/5205283 to your computer and use it in GitHub Desktop.
Save shhyou/5205283 to your computer and use it in GitHub Desktop.
Obtained by defunctionalizing match', thus obtaining a 2-state PDA.
-- Defunctionalizing match' -- we obtain a 2-state push-down automaton!
-- 1) https://gist.github.com/suhorng/5204442
-- 2) https://gist.github.com/suhorng/5204636
data Cont = Cont0
| Cont1 Cont
match'' :: String -> Bool
match'' s = trace s Cont0
where trace :: String -> Cont -> Bool
trace ('0':xs) k = trace xs (Cont1 k)
trace xs k = applyCont k xs
applyCont :: Cont -> String -> Bool
applyCont Cont0 xs = null xs
applyCont (Cont1 k) ('1':xs') = applyCont k xs'
applyCont _ _ = False
-- Note that Cont is isomorphic to nat -- which represents the count of 0s!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment