diff options
author | Joe Zhao <ztuowen@gmail.com> | 2015-04-04 17:38:20 +0800 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2015-04-04 17:38:20 +0800 |
commit | 13c0046a6dbd41b15358e76856922144ac76e768 (patch) | |
tree | dfee06a0f90b0b0b6048eafec7c46da253c79328 /H47.hs | |
parent | b47befab3696c40c710ee80f366fa376ec967b30 (diff) | |
download | h99-13c0046a6dbd41b15358e76856922144ac76e768.tar.gz h99-13c0046a6dbd41b15358e76856922144ac76e768.tar.bz2 h99-13c0046a6dbd41b15358e76856922144ac76e768.zip |
+46 +47 +48 +49 +50
Diffstat (limited to 'H47.hs')
-rw-r--r-- | H47.hs | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -0,0 +1,37 @@ +module H47 where +-- Any that lacks a infix precedence declaration will assume 9 + +infixl 4 `or'` +infixl 4 `nor'` +infixl 5 `xor'` +infixl 6 `and'` +infixl 6 `nand'` +infixl 3 `equ'` + +and',or',nand',nor',xor',impl',equ' :: Bool -> Bool -> Bool +not' :: Bool -> Bool + +not' True = False +not' _ = True + +and' True True = True +and' _ _ = False + +or' False False = False +or' _ _ = True + +nand' = curry $ not' . (uncurry and') + +nor' = curry $ not' . (uncurry or') + +xor' True True = False +xor' False False = False +xor' _ _ = True + +impl' a b = or' (not' a) b + +equ' = curry $ not' . (uncurry xor') + +table :: (Bool -> Bool -> Bool) -> IO () +table f = mapM_ putStrLn [show a ++ " " ++ show b ++ " " ++ show (f a b) + | a <- [True, False], b <- [True, False]] |