haskell命题逻辑

时间:2017-10-27 17:08:55

标签: haskell logic

我正在尝试在haskell中创建命题逻辑的结构。该结构包含“变量”(而不仅仅是变量)的“AND”,“OR”和“Equalities”和“Inequalities”。 我想要构建的程序应该检查一个新的“Equality”/“Inequality”是否满足以前的那些并添加它,如果出现这种情况,请删除一些,以使其正确。

data Logic a = Val a 
              | And     (Logic a) (Logic a)
              | Or      (Logic a) (Logic a)
              | Equal   (Logic a) (Logic a)
              | Inequal (Logic a) (Logic a)
              | Parenthesis (Logic a) 
              deriving (Show, Eq)

equal :: Eq a => Logic a -> Logic a -> Bool
equal (Equal a b) (Equal c d) 
    | a == c && b == d = True
    | a == d && b == c = True
    | otherwise = False

eq (Equal a b) (Inequal c d) = False
eq1 (Inequal a b) (Equal c d ) = False

inequal :: Eq a => Logic a -> Logic a -> Bool    
inequal (Inequal a b) (Inequal c d) 
    | a == c && b == d = True
    | a == d && b == c = True
    | otherwise = False

这是我到目前为止所得到的。我很困惑,因为我不知道如何处理这个问题,如果我有一个新的“不平等”或“平等”来检查如何处理它,因为我不能检查如下:

check logic = if logic == (Equal a) then something else somethingelse

非常感谢提前。

0 个答案:

没有答案