module FirstOrderTheory.Syntax(
Literal, Atom, Term,
atomArgs, predicateName, isFunctionWithName,
isNeg, getAtom, varName, intVal, funcArgs,
lit, nLit, atom, func, var, intConst) where
import Data.List as L
import FirstOrderTheory.Utils
data Literal
= Lit Atom
| Neg Atom
deriving (Eq, Ord)
lit = Lit
nLit = Neg
isNeg :: Literal -> Bool
isNeg (Neg _) = True
isNeg _ = False
getAtom :: Literal -> Atom
getAtom (Neg a) = a
getAtom (Lit a) = a
instance Show Literal where
show (Lit p) = show p
show (Neg p) = "~" ++ show p
data Atom = Atom Name [Term]
deriving (Eq, Ord)
atom = Atom
atomArgs (Atom _ args) = args
predicateName (Atom n _) = n
instance Show Atom where
show (Atom name args) = name ++ "[" ++ (L.intercalate ", " $ L.map show args) ++ "]"
data Term
= Function Name [Term]
| Variable Name
| Integer Int
deriving (Eq, Ord)
func = Function
var = Variable
intConst = Integer
isFunctionWithName n (Function m _) = n == m
isFunctionWithName _ _ = False
varName (Variable n) = n
funcArgs (Function _ args) = args
intVal (Integer i) = i
instance Show Term where
show (Integer val) = show val
show (Variable name) = name
show (Function name args) = name ++ "(" ++ (L.intercalate ", " $ L.map show args) ++ ")"