Advertisement
ChristophX86

Untitled

Oct 26th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data Logic = O | I | A | B | C | Not Logic | And Logic Logic | Or Logic Logic deriving (Eq, Show, Read)
  2.  
  3. eval :: Logic -> Logic
  4.  
  5.  
  6. eval (Not O) = I
  7. eval (Not I) = O
  8. eval (Not (Not x)) = eval x
  9.  
  10. eval (And O _) = O
  11. eval (And _ O) = O
  12. eval (And I x) = eval x
  13. eval (And x I) = eval x
  14. eval (And x y)
  15.     | x == y       = x
  16.     | x == (Not y) = O
  17.     | (Not x) == y = O
  18.     | otherwise    = (And (eval x) (eval y))
  19.  
  20. eval (Or I _) = I
  21. eval (Or _ I) = I
  22. eval (Or O x) = eval x
  23. eval (Or x O) = eval x
  24. eval (Or x y)
  25.     | x == y       = x
  26.     | x == (Not y) = I
  27.     | (Not x) == y = I
  28.     | otherwise    = (Or (eval x) (eval y))
  29.  
  30. eval x = x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement