Last active
December 15, 2015 04:50
-
-
Save shhyou/5204442 to your computer and use it in GitHub Desktop.
Examples from 'Defunctionalization at Work' (paper written by Olivier Danvy and Lasse R. Nielsen).
Matching the context-free language L := {0^n1^n | n \in N} where N = {0, 1, 2, ...}
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
-- L = {0^n 1^n | n \in N} | |
match :: String -> Bool | |
match s = case trace s of | |
Just [] -> True | |
_ -> False | |
where trace :: String -> Maybe String | |
trace ('0':xs) = do | |
remainString <- trace xs | |
(case remainString of | |
'1':xs' -> return xs' | |
_ -> Nothing) | |
trace xs = return xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment