summaryrefslogtreecommitdiff
path: root/46-50/46.hs
blob: 30602e0cf7ff0f4e6f1ce46be8f2d02a627ce78b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
and', or', nand', nor', xor', impl', equ' :: Bool -> Bool -> Bool
not' :: Bool -> Bool

not' True = False
not' False = True

and' True True = True
and' _ _ = False

or' False False = False
or' _ _ = True

xor' True False = True
xor' False True = True
xor' _ _ = False

equ' a b = (not' a) `xor'` b
impl' a b = (not' a) `or'` b

nand' a = not' . and' a
nor' a = not' . or' a

table :: (Bool -> Bool -> Bool) -> IO ()
table f = mapM_ putStrLn [show a ++ " " ++ show b ++ " " ++ (show $ f a b)
                            | let bin = [True, False], a <- bin, b <- bin]