diff --git a/haskell-experiments/src/Datalog/NaiveDatabase.hs b/haskell-experiments/src/Datalog/NaiveDatabase.hs index ade7f27..19c3d10 100644 --- a/haskell-experiments/src/Datalog/NaiveDatabase.hs +++ b/haskell-experiments/src/Datalog/NaiveDatabase.hs @@ -34,7 +34,7 @@ data RuleElement = -- entry occurring in a head or body relation - constant or v deriving (Show, Eq) data RuleBodyElement = RuleBodyElement { - _subRelationName :: Text, + _subRelationId :: RelationId, _ruleElements :: [RuleElement] } deriving (Show, Eq) @@ -44,22 +44,16 @@ data RelationRule = RelationRule { } deriving (Show, Eq) data Relation = Relation { - _name :: Text, + _name :: RelationId, _arity :: Int, _tuples :: Set [Constant], _rules :: [RelationRule] } deriving (Show, Eq) --- newtype RelationId = RelationId 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, @@ -211,7 +205,7 @@ withFactsAndRules facts rules = fromBodyConstraint :: BodyConstraint -> RuleBodyElement fromBodyConstraint (BodyConstraint subRelation elements) = RuleBodyElement { - _subRelationName = _name subRelation, + _subRelationId = _name subRelation, _ruleElements = toRuleElement <$> elements } toRuleElement :: ConstraintElement -> RuleElement diff --git a/haskell-experiments/test/Test/Datalog/NaiveDatabaseSpec.hs b/haskell-experiments/test/Test/Datalog/NaiveDatabaseSpec.hs index e18a460..b6a67b3 100644 --- a/haskell-experiments/test/Test/Datalog/NaiveDatabaseSpec.hs +++ b/haskell-experiments/test/Test/Datalog/NaiveDatabaseSpec.hs @@ -54,13 +54,13 @@ spec = do headVariables = [ "X", "Y", "Z" ], bodyElements = [ RuleBodyElement { - _subRelationName = "parent", + _subRelationId = "parent", _ruleElements = [ RuleElementVariable "X", RuleElementVariable "Z" ] }, RuleBodyElement { - _subRelationName = "ancestor", + _subRelationId = "ancestor", _ruleElements = [ RuleElementVariable "Z",RuleElementVariable "Y" ]