Skip to content

Commit

Permalink
drop anonymous variables when considering if negation is safe
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Jan 6, 2021
1 parent e8aa5eb commit 7a4c963
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Datalog/Rule.elm
Expand Up @@ -89,6 +89,7 @@ isNegationSafe (Rule _ body_) =
|> (\{ positive, negative } ->
negative
|> Set.dropIf (Set.memberOf positive)
|> Set.dropIf ((==) Term.Anonymous)
|> Set.isEmpty
)

Expand Down
8 changes: 8 additions & 0 deletions tests/Datalog/RuleTests.elm
Expand Up @@ -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
Expand Down

0 comments on commit 7a4c963

Please sign in to comment.