Skip to content

Instantly share code, notes, and snippets.

@shhyou
Last active December 15, 2015 04:50
Show Gist options
  • Save shhyou/5204442 to your computer and use it in GitHub Desktop.
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, ...}
-- 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