simplified addFact
This commit is contained in:
parent
b8db9477c0
commit
2f911a9f39
@ -16,9 +16,7 @@ import Data.Maybe
|
||||
import Data.Set (Set)
|
||||
import Data.Set qualified as Set
|
||||
import Data.Text (Text)
|
||||
import Data.Void
|
||||
import Datalog.DatalogParser (Head (HeadSingle), Literal (..), Statement (..), Term (..), parseDatalog)
|
||||
import Text.Megaparsec (ParseErrorBundle)
|
||||
import Datalog.DatalogParser (Literal (..), Statement (..), Term (..), parseDatalog)
|
||||
import Datalog.Rules
|
||||
import Datalog.DatalogDB
|
||||
|
||||
@ -47,12 +45,11 @@ instance DatalogDB NaiveDatabase where
|
||||
|
||||
addFact :: Literal -> NaiveDatabase -> NaiveDatabase
|
||||
addFact (Literal neg relationName terms) db@(NaiveDatabase relationMap constantSet) =
|
||||
NaiveDatabase newRelationMap newConstantSet
|
||||
insertRelation (addConstants db extraConstants) newRelation
|
||||
where
|
||||
newArity = length terms
|
||||
newRelation = lookupRelation0 relationName db newArity (Set.singleton terms)
|
||||
newRelationMap = Map.insert relationName newRelation relationMap
|
||||
newConstantSet = Set.union constantSet $ Set.fromList terms
|
||||
extraConstants = Set.fromList terms
|
||||
|
||||
addRule :: (Literal, [Literal]) -> NaiveDatabase -> NaiveDatabase
|
||||
addRule (ruleHead, body) db =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user