Skip to content

Instantly share code, notes, and snippets.

@jrm2k6
Created January 23, 2014 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrm2k6/8583498 to your computer and use it in GitHub Desktop.
Save jrm2k6/8583498 to your computer and use it in GitHub Desktop.
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