Last active
June 10, 2019 16:49
Take a proposition and find all the variables it contains.
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
-- 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