Created
March 20, 2013 14:53
-
-
Save shhyou/5205283 to your computer and use it in GitHub Desktop.
Obtained by defunctionalizing match', thus obtaining a 2-state PDA.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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