'addConstants' API method

This commit is contained in:
Felix Dilke 2026-01-30 10:55:19 +00:00
parent 72f973c195
commit d8d2c51dec
2 changed files with 9 additions and 1 deletions

View File

@ -23,4 +23,5 @@ class DatalogDB db where
emptyDB :: db emptyDB :: db
lookupRelation :: db -> Text -> Maybe Relation lookupRelation :: db -> Text -> Maybe Relation
insertRelation :: db -> Relation -> db insertRelation :: db -> Relation -> db
addRule :: (Literal, [Literal]) -> db -> db addRule :: (Literal, [Literal]) -> db -> db
addConstants :: db -> Set Constant -> db

View File

@ -63,6 +63,12 @@ instance DatalogDB NaiveDatabase where
relationMap' = Map.insert relationName relation' relationMap relationMap' = Map.insert relationName relation' relationMap
constants' = constants db' constants' = constants db'
addConstants :: NaiveDatabase -> Set Constant -> NaiveDatabase
addConstants db newConstants =
db {
constants = Set.union newConstants (constants db)
}
lookupRelation0 :: DatalogDB db => Text -> db -> Int -> Set [Constant] -> Relation lookupRelation0 :: DatalogDB db => Text -> db -> Int -> Set [Constant] -> Relation
lookupRelation0 relationName db newArity tuples = lookupRelation0 relationName db newArity tuples =
case lookupRelation db relationName of case lookupRelation db relationName of
@ -139,6 +145,7 @@ digestHead db relation (Literal neg relationName terms) =
headTermToElement (Var name) = headTermToElement (Var name) =
RuleElementVariable $ lookupVariable name variableNames RuleElementVariable $ lookupVariable name variableNames
headTermToElement constant = RuleElementConstant constant headTermToElement constant = RuleElementConstant constant
-- db' = insertRelation db relation
relationMap :: Map RelationId Relation = relations db relationMap :: Map RelationId Relation = relations db
relationMap' = Map.insert relationName relation relationMap relationMap' = Map.insert relationName relation relationMap
extraVariables = headTermToElement <$> terms extraVariables = headTermToElement <$> terms