diff --git a/haskell-experiments/src/Datalog/InMemoryDB.hs b/haskell-experiments/src/Datalog/InMemoryDB.hs index 980fe85..1996555 100644 --- a/haskell-experiments/src/Datalog/InMemoryDB.hs +++ b/haskell-experiments/src/Datalog/InMemoryDB.hs @@ -49,7 +49,7 @@ instance DatalogDB InMemoryDB where relationNames db = keys (_relations db) allConstants :: InMemoryDB -> Set Constant - allConstants db = _constants db + allConstants = _constants withFacts :: [Text] -> InMemoryDB withFacts = diff --git a/haskell-experiments/src/Datalog/NaiveQE.hs b/haskell-experiments/src/Datalog/NaiveQE.hs index 4f1124e..6040f9c 100644 --- a/haskell-experiments/src/Datalog/NaiveQE.hs +++ b/haskell-experiments/src/Datalog/NaiveQE.hs @@ -77,23 +77,21 @@ computeHerbrand db = where (facts, wasChanged) = newFacts latestRelation = facts Map.! (_name relation) - knownTuples :: Set [Constant] = - _tuples $ latestRelation + knownTuples :: Set [Constant] = _tuples latestRelation extraTuples = do varmap <- allMaps headVars (Set.toList $ allConstants db) - let tuple = (\name -> varmap Map.! name) <$> headVars + let tuple = (varmap Map.!) <$> headVars guard $ not $ Set.member tuple knownTuples let satisfied :: RuleBodyElement -> Bool satisfied (RuleBodyElement subRelationId ruleElements) = let subRelation = facts Map.! subRelationId - mappedTuple = ruleElements <&> \ruleElement -> - case ruleElement of - RuleElementConstant constant -> constant - RuleElementVariable index -> tuple !! index + mappedTuple = ruleElements <&> \case + RuleElementConstant constant -> constant + RuleElementVariable index -> tuple !! index in Set.member mappedTuple (_tuples subRelation) guard $ all satisfied bodyElements return tuple - stillChanged = wasChanged || (not (null extraTuples)) + stillChanged = wasChanged || not (null extraTuples) updatedTuples = Set.union knownTuples $ Set.fromList extraTuples updatedFacts = Map.insert (_name relation) ( latestRelation { _tuples = updatedTuples }) facts diff --git a/haskell-experiments/test/Test/Datalog/DigestedQuerySpec.hs b/haskell-experiments/test/Test/Datalog/DigestedQuerySpec.hs index 5b9c283..1ce534a 100644 --- a/haskell-experiments/test/Test/Datalog/DigestedQuerySpec.hs +++ b/haskell-experiments/test/Test/Datalog/DigestedQuerySpec.hs @@ -11,8 +11,12 @@ module Test.Datalog.DigestedQuerySpec where import Test.Hspec import Datalog.DatalogParser -import Datalog.DigestedQuery (DigestedQuery(..), DigestedQueryCondition(..), DigestedQueryEntry(..)) -import Datalog.DigestedQuery (digestQuery) +import Datalog.DigestedQuery + ( DigestedQuery(..), + DigestedQueryCondition(..), + DigestedQueryEntry(..), + digestQuery ) + spec :: Spec spec = do diff --git a/haskell-experiments/test/Test/Datalog/NaiveQESpec.hs b/haskell-experiments/test/Test/Datalog/NaiveQESpec.hs index 726ed44..c5ce504 100644 --- a/haskell-experiments/test/Test/Datalog/NaiveQESpec.hs +++ b/haskell-experiments/test/Test/Datalog/NaiveQESpec.hs @@ -16,10 +16,7 @@ module Test.Datalog.NaiveQESpec where import Test.Hspec import Datalog.InMemoryDB (InMemoryDB) import qualified Datalog.InMemoryDB as InMemoryDB -import Datalog.QueryEngine (QueryEngine(query)) -import qualified Datalog.QueryEngine as QueryEngine -import qualified Datalog.NaiveQE as NaiveQE -import Datalog.QueryEngine (queryEngine) +import Datalog.QueryEngine (QueryEngine(query), queryEngine) import Datalog.NaiveQE spec :: Spec diff --git a/haskell-experiments/test/Test/Utility/UtilitySpec.hs b/haskell-experiments/test/Test/Utility/UtilitySpec.hs index b2c0ad3..f232e19 100644 --- a/haskell-experiments/test/Test/Utility/UtilitySpec.hs +++ b/haskell-experiments/test/Test/Utility/UtilitySpec.hs @@ -26,7 +26,7 @@ spec = do allMaps @Int @Int [] [1] `shouldBe` [Map.empty] allMaps @Int @Int [1] [] `shouldBe` [] allMaps [1] [True] `shouldBe` [Map.singleton 1 True] - uncharacteristic <$> (allMaps [1, 2, 3] [True, False]) `shouldMatchList` [ + uncharacteristic <$> allMaps [1, 2, 3] [True, False] `shouldMatchList` [ [1,2,3], [1,2], [1,3], [1], [2, 3], [2], [3], [] ]