From b816bb4caece9a50dc44cfb330562cfcf139b7df Mon Sep 17 00:00:00 2001 From: Felix Dilke Date: Fri, 30 Jan 2026 14:28:51 +0000 Subject: [PATCH] simplified addRule --- haskell-experiments/src/Datalog/NaiveDatabase.hs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/haskell-experiments/src/Datalog/NaiveDatabase.hs b/haskell-experiments/src/Datalog/NaiveDatabase.hs index 8938c88..f38d9bc 100644 --- a/haskell-experiments/src/Datalog/NaiveDatabase.hs +++ b/haskell-experiments/src/Datalog/NaiveDatabase.hs @@ -53,7 +53,8 @@ instance DatalogDB NaiveDatabase where addRule :: (Literal, [Literal]) -> NaiveDatabase -> NaiveDatabase addRule (ruleHead, body) db = - NaiveDatabase relationMap' constants' where + insertRelation db' newRelation + where relationName = predName ruleHead terms = arguments ruleHead newArity = length terms @@ -61,13 +62,10 @@ instance DatalogDB NaiveDatabase where context = digestHead db relation ruleHead context' = foldr digestBody context body db' = _db context' - relationMap = relations db' - relation' = appendRule relation RelationRule { + newRelation = appendRule relation RelationRule { headVariables = _variableNames context' , bodyElements = toRuleBodyElement <$> _bodyConstraints context' } - relationMap' = Map.insert relationName relation' relationMap - constants' = constants db' addConstants :: NaiveDatabase -> Set Constant -> NaiveDatabase addConstants db newConstants =