Created
January 23, 2014 17:56
-
-
Save jrm2k6/8583498 to your computer and use it in GitHub Desktop.
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
infixl 4 `and'` | |
and' :: Bool -> Bool -> Bool | |
and' False _ = False | |
and' _ False = False | |
and' _ _ = True | |
infixl 4 `or'` | |
or' :: Bool -> Bool -> Bool | |
or' True _ = True | |
or' _ True = True | |
or' _ _ = False | |
infixl 9 `not'` | |
not' :: Bool -> Bool | |
not' True = False | |
not' False = True | |
infixl 4 `nand'` | |
nand' :: Bool -> Bool -> Bool | |
nand' a b = not' $ and' a b | |
infixl 4 `nor'` | |
nor' :: Bool -> Bool -> Bool | |
nor' a b = not' $ or' a b | |
infixl 4 `xor'` | |
xor' :: Bool -> Bool -> Bool | |
xor' True False = True | |
xor' True True = False | |
xor' False False = False | |
xor' False True = True | |
infixl 3 `impl'` | |
impl' :: Bool -> Bool -> Bool | |
impl' a b = or' (not' a) b | |
infixl 2 `eq'` | |
eq' :: Bool -> Bool -> Bool | |
eq' a b = and' (impl' a b) (impl' b a) | |
table :: (Bool -> Bool -> Bool) -> IO() | |
table logicalExp = let values = [(x,y, logicalExp x y) | x <- [True, False], y <- [True, False]] | |
in sequence_ [putStrLn ((show a) ++ "," ++ (show b) ++ "," ++ (show c)) | (a,b,c) <- values] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment