Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created September 30, 2015 20:17
Show Gist options
  • Save amalloy/e385053eea25e3743c90 to your computer and use it in GitHub Desktop.
Save amalloy/e385053eea25e3743c90 to your computer and use it in GitHub Desktop.
freeVars :: Exp -> [Id]
freeVars = nub . go [] where
go env (Var v) | v `elem` env = []
| otherwise = [v]
go _ (Nat _) = []
go _ (Op _) = []
go env (Lam arg body) = go (arg:env) body
go env (App f x) = go env f ++ go env x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment