From 7a4c963ee776082e682bc4b934e934701b12cda2 Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Tue, 5 Jan 2021 20:27:31 -0600 Subject: [PATCH] drop anonymous variables when considering if negation is safe --- src/Datalog/Rule.elm | 1 + tests/Datalog/RuleTests.elm | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/Datalog/Rule.elm b/src/Datalog/Rule.elm index a9f9c14..731b17a 100644 --- a/src/Datalog/Rule.elm +++ b/src/Datalog/Rule.elm @@ -89,6 +89,7 @@ isNegationSafe (Rule _ body_) = |> (\{ positive, negative } -> negative |> Set.dropIf (Set.memberOf positive) + |> Set.dropIf ((==) Term.Anonymous) |> Set.isEmpty ) diff --git a/tests/Datalog/RuleTests.elm b/tests/Datalog/RuleTests.elm index d000552..94ab1dd 100644 --- a/tests/Datalog/RuleTests.elm +++ b/tests/Datalog/RuleTests.elm @@ -38,6 +38,14 @@ ruleTest = , negative (atom "reachable" [ variable "a", variable "b" ]) ] |> Expect.ok + , test "negative terms which are introduced outside the head are still allowed if they appear in positive form" <| + \_ -> + rule + (atom "peopleWithoutEmails" [ variable "Name" ]) + [ positive (atom "people" [ variable "Id", variable "Name" ]) + , negative (atom "peopleToEmails" [ variable "Id", anonymous ]) + ] + |> Expect.ok , test "negative terms are not allowed if they don't also appear in a positive form" <| \_ -> rule