adjusting types, developing addFact

This commit is contained in:
Felix Dilke 2026-01-22 10:57:11 +00:00
parent 52fad6e4a1
commit 36622caf8b

View File

@ -24,24 +24,28 @@ data Value =
data NaiveDatabase = NaiveDatabase {
relations :: Map RelationId Relation,
constants :: Set ConstantId
constants :: Set Constant
}
data Relation = Relation {
arity :: Int,
tuples :: Set [ConstantId]
tuples :: Set [Constant]
}
newtype RelationId = RelationId Text
deriving (Eq, Ord, Show)
-- newtype RelationId = RelationId Text
-- deriving (Eq, Ord, Show)
newtype ConstantId = ConstantId Text
deriving (Eq, Ord, Show)
-- Our constants will be the terms of the Datalog grammar - ints/variables/symbols
type Constant = Term
type RelationId = Text
-- newtype Constant = Constant Text
-- deriving (Eq, Ord, Show)
emptyDB :: NaiveDatabase
emptyDB = NaiveDatabase {
relations = Map.empty,
constants = Set.empty
constants = Set.empty -- the Herbrand universe
}
withFacts :: [Text] -> NaiveDatabase
@ -54,8 +58,13 @@ withFacts facts =
Right otherStatement -> throw $ NonFactException factText otherStatement
Left ex -> throw $ CannotParseStatementException factText ex
addFact :: NaiveDatabase -> Literal -> NaiveDatabase
addFact db lit =
db
addFact (NaiveDatabase relations constants) (Literal neg relationName terms) =
NaiveDatabase newRelations newConstants where
newRelations =
case Map.lookup relationName relations of
Nothing -> relations
Just relation -> relations
newConstants = Set.union constants $ Set.fromList terms
query :: NaiveDatabase -> Text -> Text
query db qText =