module Fol where
data Id = Qname String String
deriving (Eq,Ord,Show)
data Term =
Fvar Id
| Ffun Id
| Fcon Id
| Fapp Term Term
deriving (Eq,Ord,Show)
data ClBody = ClEqual Term Term
data Clause =
Cl ClBody
| ClNot ClBody
| ClOr [Clause]
| ClInline Id
| ClNinline Id
type Def = (Id, Clause)
type Prop = (Id,[Id],[Clause],[Clause])
-- ProofObl = name, program clauses, proposition clauses
type ProofObl = (Id,[Clause],[Clause])
type Library = (String, [Fol.Def], [Fol.Prop])
{- Finding all the function names used in a term, body, or clause -}
fvTerm :: [Id] -> Term -> [Id]
fvTerm fv t =
case t of
Fvar _ -> fv
Ffun s -> if elem s fv then fv else s:fv
Fcon _ -> fv
Fapp t1 t2 -> fvTerm (fvTerm fv t1) t2
fvClBody :: [Id] -> ClBody -> [Id]
fvClBody fv (ClEqual t1 t2) = fvTerm (fvTerm fv t1) t2
fvClause :: [Id] -> Clause -> [Id]
fvClause fv c =
case c of
Cl b -> fvClBody fv b
ClNot b -> fvClBody fv b
ClOr lc -> foldl fvClause fv lc
ClInline id -> fv
ClNinline id -> fv