From d5beb57492b012553b2118de0ada85617a01ff44 Mon Sep 17 00:00:00 2001 From: Felix Dilke Date: Tue, 10 Feb 2026 17:36:41 +0000 Subject: [PATCH] yet more herbrand code --- haskell-experiments/src/Datalog/NaiveQE.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/haskell-experiments/src/Datalog/NaiveQE.hs b/haskell-experiments/src/Datalog/NaiveQE.hs index 6192a9f..c9e54dc 100644 --- a/haskell-experiments/src/Datalog/NaiveQE.hs +++ b/haskell-experiments/src/Datalog/NaiveQE.hs @@ -67,13 +67,21 @@ computeHerbrand db = amalgamateRelationSub newFacts relation = foldr amalgamateRule newFacts (_rules relation) where amalgamateRule :: RelationRule -> NewFacts -> NewFacts - amalgamateRule (RelationRule headVars body) newFacts = + amalgamateRule (RelationRule headVars bodyElements) newFacts = newFacts where (facts, changed) = newFacts - knownTuples :: Set [Constant] = _tuples $ facts Map.! (_name relation) + knownTuples :: Set [Constant] = + _tuples $ facts Map.! (_name relation) extraTuples = do varmap <- allMaps headVars (Set.toList $ allConstants db) let tuple = (\name -> varmap Map.! name) <$> headVars guard $ not $ Set.member tuple knownTuples + let twig :: Int -> Int -> Int + twig x y = x + y + satisfied :: RuleBodyElement -> Bool + satisfied (RuleBodyElement subRelationId ruleElements) = all (satisfiedSub (facts Map.! subRelationId)) ruleElements + satisfiedSub :: Relation -> RuleElement -> Bool + satisfiedSub subRelation ruleElement = True + guard $ all satisfied bodyElements return varmap