filling out the DB

This commit is contained in:
Felix Dilke 2026-01-21 18:01:06 +00:00
parent 73aec57151
commit 52fad6e4a1
2 changed files with 49 additions and 6 deletions

View File

@ -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

View File

@ -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'