resolution/app/FOLSyntax.hs
2023-06-07 11:04:00 +02:00

32 lines
No EOL
1 KiB
Haskell

module FOLSyntax where
data Term = Var String | Fun String [Term] deriving (Eq, Ord)
data Formula
= Pred String [Term]
| Neg Formula
| Conj Formula Formula
| Disj Formula Formula
| Impl Formula Formula
| All String Formula
| Exists String Formula
| T
| F
deriving (Eq, Ord)
instance Show Term where
show (Var x) = x
show (Fun f []) = f
show (Fun f (x : xs)) = f ++ "(" ++ show x ++ foldr ((++) . (", "++) . show) ")" xs
instance Show Formula where
show (Pred p []) = p
show (Pred p (x : xs)) = p ++ "(" ++ show x ++ foldr ((++) . (", "++) . show) ")" xs
show (Neg f) = "!(" ++ show f ++ ")"
show (Conj f1 f2) = "(" ++ show f1 ++ " /\\ " ++ show f2 ++ ")"
show (Disj f1 f2) = "(" ++ show f1 ++ " \\/ " ++ show f2 ++ ")"
show (Impl f1 f2) = "(" ++ show f1 ++ " -> " ++ show f2 ++ ")"
show (All x f) = "(forall " ++ x ++ ". " ++ show f ++ ")"
show (Exists x f) = "(exists " ++ x ++ ". " ++ show f ++ ")"
show T = "true"
show F = "false"