simplified addRule
This commit is contained in:
parent
2f911a9f39
commit
b816bb4cae
@ -53,7 +53,8 @@ instance DatalogDB NaiveDatabase where
|
|||||||
|
|
||||||
addRule :: (Literal, [Literal]) -> NaiveDatabase -> NaiveDatabase
|
addRule :: (Literal, [Literal]) -> NaiveDatabase -> NaiveDatabase
|
||||||
addRule (ruleHead, body) db =
|
addRule (ruleHead, body) db =
|
||||||
NaiveDatabase relationMap' constants' where
|
insertRelation db' newRelation
|
||||||
|
where
|
||||||
relationName = predName ruleHead
|
relationName = predName ruleHead
|
||||||
terms = arguments ruleHead
|
terms = arguments ruleHead
|
||||||
newArity = length terms
|
newArity = length terms
|
||||||
@ -61,13 +62,10 @@ instance DatalogDB NaiveDatabase where
|
|||||||
context = digestHead db relation ruleHead
|
context = digestHead db relation ruleHead
|
||||||
context' = foldr digestBody context body
|
context' = foldr digestBody context body
|
||||||
db' = _db context'
|
db' = _db context'
|
||||||
relationMap = relations db'
|
newRelation = appendRule relation RelationRule {
|
||||||
relation' = appendRule relation RelationRule {
|
|
||||||
headVariables = _variableNames context'
|
headVariables = _variableNames context'
|
||||||
, bodyElements = toRuleBodyElement <$> _bodyConstraints context'
|
, bodyElements = toRuleBodyElement <$> _bodyConstraints context'
|
||||||
}
|
}
|
||||||
relationMap' = Map.insert relationName relation' relationMap
|
|
||||||
constants' = constants db'
|
|
||||||
|
|
||||||
addConstants :: NaiveDatabase -> Set Constant -> NaiveDatabase
|
addConstants :: NaiveDatabase -> Set Constant -> NaiveDatabase
|
||||||
addConstants db newConstants =
|
addConstants db newConstants =
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user