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