Skip to content

Instantly share code, notes, and snippets.

@rodrigogiraoserrao
Last active June 10, 2019 16:49
Take a proposition and find all the variables it contains.
-- given a proposition, return a list with all the variables that show up
collectVars :: Prop -> [String]
collectVars (Const _ ) = []
collectVars (Var s ) = [s]
collectVars (Neg prop) = nub $ collectVars prop
-- these four patterns are rather annoying
collectVars (And p1 p2) = nub $ (collectVars p1) ++ (collectVars p2)
collectVars (Or p1 p2) = nub $ (collectVars p1) ++ (collectVars p2)
collectVars (Equiv p1 p2) = nub $ (collectVars p1) ++ (collectVars p2)
collectVars (Impl p1 p2) = nub $ (collectVars p1) ++ (collectVars p2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment