From a70cf1f6bf9b21c30e57b768e3f2ca62a93509f8 Mon Sep 17 00:00:00 2001 From: Felix Dilke Date: Tue, 3 Feb 2026 16:11:41 +0000 Subject: [PATCH] slowly figuring out how to populate the herbrand --- haskell-experiments/src/Datalog/NaiveQE.hs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/haskell-experiments/src/Datalog/NaiveQE.hs b/haskell-experiments/src/Datalog/NaiveQE.hs index 120056f..cae0044 100644 --- a/haskell-experiments/src/Datalog/NaiveQE.hs +++ b/haskell-experiments/src/Datalog/NaiveQE.hs @@ -19,6 +19,8 @@ import Data.Map qualified as Map import Datalog.DatalogDB import Datalog.DatalogParser import Control.Exception +import Data.Maybe +import Data.Functor ((<&>)) data (DatalogDB db) => NaiveQE db = NaiveQE { @@ -41,8 +43,16 @@ instance QueryEngine NaiveQE where computeHerbrand :: (DatalogDB db) => db -> Map Text Relation computeHerbrand db = - computeHerbrandSub Map.empty where - computeHerbrandSub :: Map Text Relation -> Map Text Relation - computeHerbrandSub facts = facts - -- for_ (Map.toList myMap) $ \(k,v) -> + computeHerbrandSub initialFacts where + initialFacts :: Map Text Relation = + Map.fromList $ catMaybes $ relationNames db <&> (\relationName -> do + relation <- lookupRelation db relationName + pure (relationName, relation)) + updateFacts :: Map Text Relation -> Maybe (Map Text Relation) + updateFacts facts = Nothing -- Just facts + computeHerbrandSub :: Map Text Relation -> Map Text Relation + computeHerbrandSub facts = + case updateFacts facts of + Just moreFacts -> computeHerbrandSub moreFacts + Nothing -> facts