From 52fad6e4a1d69e714d233e48b875e136b25a284c Mon Sep 17 00:00:00 2001 From: Felix Dilke Date: Wed, 21 Jan 2026 18:01:06 +0000 Subject: [PATCH] filling out the DB --- .../src/Datalog/NaiveDatabase.hs | 17 +++++++-- .../test/Test/Datalog/NaiveDatabaseSpec.hs | 38 +++++++++++++++++-- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/haskell-experiments/src/Datalog/NaiveDatabase.hs b/haskell-experiments/src/Datalog/NaiveDatabase.hs index cd6b7e5..a8c9ef9 100644 --- a/haskell-experiments/src/Datalog/NaiveDatabase.hs +++ b/haskell-experiments/src/Datalog/NaiveDatabase.hs @@ -23,14 +23,25 @@ data Value = ValueSymbol String data NaiveDatabase = NaiveDatabase { - relations :: Map Text Int, - values :: Set Value + relations :: Map RelationId Relation, + constants :: Set ConstantId } +data Relation = Relation { + arity :: Int, + tuples :: Set [ConstantId] +} + +newtype RelationId = RelationId Text + deriving (Eq, Ord, Show) + +newtype ConstantId = ConstantId Text + deriving (Eq, Ord, Show) + emptyDB :: NaiveDatabase emptyDB = NaiveDatabase { relations = Map.empty, - values = Set.empty + constants = Set.empty } withFacts :: [Text] -> NaiveDatabase diff --git a/haskell-experiments/test/Test/Datalog/NaiveDatabaseSpec.hs b/haskell-experiments/test/Test/Datalog/NaiveDatabaseSpec.hs index 5155982..654a406 100644 --- a/haskell-experiments/test/Test/Datalog/NaiveDatabaseSpec.hs +++ b/haskell-experiments/test/Test/Datalog/NaiveDatabaseSpec.hs @@ -23,6 +23,19 @@ import qualified Datalog.NaiveDatabase as NaiveDatabase -- checkEval text expectedVal = -- fmap eval (parse parseExpr "" text) `shouldBe` Right expectedVal +-- getConfig :: IO Config +-- getConfig = do +-- env <- lookupEnv "APP_ENV" +-- let fallbackHosts = +-- [ "localhost:8080" +-- , "127.0.0.1:9000" +-- , "backup.example.com" +-- ] +-- pure Config +-- { port = 3000 +-- , hosts = fromMaybe fallbackHosts env +-- , logLevel = Info +-- } spec :: Spec spec = do @@ -30,7 +43,26 @@ spec = do it "..." $ do 1 `shouldBe` (1 :: Int) it "can accept facts and do basic queries" $ do - let twig = [ "xx", "yy "] - let pig = [ "parent(\"alice\", \"bob\").", "parent(\"bob\", \"carol\")." ] - let db = NaiveDatabase.withFacts [ "parent(\"alice\", \"bob\").", "parent(\"bob\", \"carol\")." ] + -- let fallbackHosts = + -- [ "localhost:8080" + -- , "127.0.0.1:9000" + -- , "backup.example.com" + -- ] + -- let names = + -- [ "Alice" + -- , "Bob" + -- , "Charlie" + -- , "Daphne" + -- , "Eve" + -- ] + -- let twig = + -- [ "xx" + -- , "yy " ] + -- let pig = + -- [ "parent(\"alice\", \"bob\")." + -- , "parent(\"bob\", \"carol\")." + -- ] + let db = NaiveDatabase.withFacts + [ "parent(\"alice\", \"bob\")." + , "parent(\"bob\", \"carol\")." ] query db"?- parent(alice,X)." `shouldBe` "#NYI" -- ideally, 'bob'