diff --git a/haskell-experiments/src/Datalog/NaiveDatabase.hs b/haskell-experiments/src/Datalog/NaiveDatabase.hs index 398bddb..5b5f833 100644 --- a/haskell-experiments/src/Datalog/NaiveDatabase.hs +++ b/haskell-experiments/src/Datalog/NaiveDatabase.hs @@ -116,8 +116,7 @@ maybeConstant (RuleElementConstant constant) = Just constant maybeConstant _ = Nothing withFactsAndRules :: [Text] -> [Text] -> NaiveDatabase -withFactsAndRules facts = - foldr (addRule . extractRule) (withFacts facts) +withFactsAndRules facts = foldr (addRule . extractRule) (withFacts facts) where extractRule :: Text -> (Literal, [Literal]) extractRule ruleText = @@ -179,18 +178,18 @@ withFactsAndRules facts = terms = arguments ruleHead newArity = length terms relation = lookupRelation relationName (relations db) newArity Set.empty - context' = digestHead db relation ruleHead - context'' = foldl digestBody context' body - db' = _db context'' + context = digestHead db relation ruleHead + context' = foldl digestBody context body + db' = _db context' relationMap = relations db' - variables' = _headEntries context'' + variables' = _headEntries context' extractVarName :: RuleElement -> Maybe Text extractVarName (RuleElementVariable varName) = Just varName extractVarName (RuleElementConstant constant) = Nothing newRule = RelationRule { headVariables = mapMaybe extractVarName variables' - , bodyElements = fromBodyConstraint <$> _bodyConstraints context'' + , bodyElements = fromBodyConstraint <$> _bodyConstraints context' } where fromBodyConstraint :: BodyConstraint -> RuleBodyElement