simplified language features and tests

This commit is contained in:
Felix Dilke 2026-01-30 16:07:23 +00:00
parent 3003a92807
commit 05b6aefabe
10 changed files with 41 additions and 98 deletions

View File

@ -77,12 +77,14 @@ test-suite haskell-exps-test
main-is: Main.hs main-is: Main.hs
-- Test dependencies. -- Test dependencies.
build-depends: base, containers, megaparsec, hspec, langfeatures build-depends: base, containers, megaparsec, hspec, langfeatures, text
other-modules: Test.OlogsSpec, other-modules: Test.OlogsSpec,
Test.SimpleParserSpec, Test.SimpleParserSpec,
Test.ArithmeticParserSpec, Test.ArithmeticParserSpec,
Test.Datalog.DatalogParserSpec, Test.Datalog.DatalogParserSpec,
Test.Datalog.InMemoryDBSpec Test.Datalog.InMemoryDBSpec
default-extensions:
OverloadedStrings
library langfeatures library langfeatures
default-language: Haskell2010 default-language: Haskell2010
@ -104,4 +106,6 @@ executable haskell-experiments
build-depends: base, containers build-depends: base, containers
main-is: Main.hs main-is: Main.hs
hs-source-dirs: src hs-source-dirs: src
default-extensions:
OverloadedStrings

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

View File

@ -1,5 +1,3 @@
{-# LANGUAGE OverloadedStrings #-}
module ArithmeticParser where module ArithmeticParser where
import Text.Megaparsec import Text.Megaparsec

View File

@ -1,6 +1,5 @@
{-# HLINT ignore "Redundant flip" #-} {-# HLINT ignore "Redundant flip" #-}
{-# LANGUAGE ImportQualifiedPost #-} {-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}

View File

@ -1,5 +1,3 @@
{-# LANGUAGE OverloadedStrings #-}
module Datalog.DatalogParser where module Datalog.DatalogParser where
import Data.Void import Data.Void

View File

@ -1,6 +1,5 @@
{-# HLINT ignore "Redundant flip" #-} {-# HLINT ignore "Redundant flip" #-}
{-# LANGUAGE ImportQualifiedPost #-} {-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE InstanceSigs #-}
@ -23,7 +22,6 @@ data InMemoryDB = InMemoryDB
, constants :: Set Constant , constants :: Set Constant
} deriving (Show, Eq) } deriving (Show, Eq)
instance DatalogDB InMemoryDB where instance DatalogDB InMemoryDB where
emptyDB :: InMemoryDB emptyDB :: InMemoryDB
emptyDB = InMemoryDB emptyDB = InMemoryDB

View File

@ -1,6 +1,5 @@
{-# HLINT ignore "Redundant flip" #-} {-# HLINT ignore "Redundant flip" #-}
{-# LANGUAGE ImportQualifiedPost #-} {-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} {-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}

View File

@ -1,4 +1,3 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedRecordDot #-} {-# LANGUAGE OverloadedRecordDot #-}
{-# HLINT ignore "Use const" #-} {-# HLINT ignore "Use const" #-}

View File

@ -1,4 +1,3 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedRecordDot #-} {-# LANGUAGE OverloadedRecordDot #-}
{-# HLINT ignore "Use const" #-} {-# HLINT ignore "Use const" #-}

View File

@ -2,7 +2,6 @@
{-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE ImportQualifiedPost #-} {-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedRecordDot #-} {-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
{-# HLINT ignore "Use const" #-} {-# HLINT ignore "Use const" #-}
{-# HLINT ignore "Unused LANGUAGE pragma" #-} {-# HLINT ignore "Unused LANGUAGE pragma" #-}
{-# HLINT ignore "Avoid lambda" #-} {-# HLINT ignore "Avoid lambda" #-}
@ -21,6 +20,7 @@ import Datalog.InMemoryDB
import Datalog.InMemoryDB qualified as InMemoryDB import Datalog.InMemoryDB qualified as InMemoryDB
import Test.Hspec import Test.Hspec
import Datalog.DatalogDB import Datalog.DatalogDB
import Data.Text
spec :: Spec spec :: Spec
spec = do spec = do
@ -55,36 +55,20 @@ spec = do
, _arity = 2 , _arity = 2
, _tuples = , _tuples =
Set.fromList $ Set.fromList $
map (Sym <$>) [["alice", "bob"], ["bob", "carol"]] Sym <<$>> [["alice", "bob"], ["bob", "carol"]]
, _rules = [] , _rules = []
} }
ancestorRule = RelationRule ancestorRule = RelationRule
{ headVariables = ["X", "Y", "Z"] { headVariables = ["X", "Y", "Z"]
, bodyElements = , bodyElements =
[ RuleBodyElement [ ruleBody "parent" [0, 2]
{ _subRelationId = "parent" , ruleBody "ancestor" [2, 1]
, _ruleElements =
[ RuleElementVariable 0
, RuleElementVariable 2
]
}
, RuleBodyElement
{ _subRelationId = "ancestor"
, _ruleElements =
[ RuleElementVariable 2
, RuleElementVariable 1
]
}
] ]
} }
ancestorRule2 = RelationRule ancestorRule2 = RelationRule
{ headVariables = ["X", "Y"] { headVariables = ["X", "Y"]
, bodyElements = , bodyElements =
[ RuleBodyElement [ ruleBody "parent" [0, 1] ]
{ _subRelationId = "parent"
, _ruleElements = [RuleElementVariable 0, RuleElementVariable 1]
}
]
} }
ancestorRelation = ancestorRelation =
Relation Relation
@ -149,30 +133,6 @@ spec = do
constants db constants db
`shouldBe` Set.empty `shouldBe` Set.empty
it "can ingest facts and rules with duplicate head entries" do
let db =
InMemoryDB.withFactsAndRules
[]
["equivalent(Q,Q) :- ."]
rule1 =
RelationRule
{ headVariables = ["Q"]
, bodyElements = []
}
equivalentRelation =
Relation
{ _arity = 2
, _name = "equivalent"
, _tuples = Set.empty
, _rules = [rule1]
}
relations db
`shouldBe` Map.singleton "equivalent" equivalentRelation
constants db
`shouldBe` Set.empty
it "can ingest a theory of equivalence relations" do it "can ingest a theory of equivalence relations" do
let db = let db =
InMemoryDB.withFactsAndRules InMemoryDB.withFactsAndRules
@ -190,33 +150,14 @@ spec = do
RelationRule RelationRule
{ headVariables = ["R", "Q"] { headVariables = ["R", "Q"]
, bodyElements = , bodyElements =
[ RuleBodyElement [ ruleBody "equivalent" [1, 0] ]
{ _subRelationId = "equivalent"
, _ruleElements =
[ RuleElementVariable 1
, RuleElementVariable 0
]
}
]
} }
rule3 = rule3 =
RelationRule RelationRule
{ headVariables = ["Q", "S", "R"] { headVariables = ["Q", "S", "R"]
, bodyElements = , bodyElements =
[ RuleBodyElement [ ruleBody "equivalent" [0, 2]
{ _subRelationId = "equivalent" , ruleBody "equivalent" [2, 1]
, _ruleElements =
[ RuleElementVariable 0
, RuleElementVariable 2
]
}
, RuleBodyElement
{ _subRelationId = "equivalent"
, _ruleElements =
[ RuleElementVariable 2
, RuleElementVariable 1
]
}
] ]
} }
equivalentRelation = equivalentRelation =
@ -249,3 +190,11 @@ spec = do
-- (<<<$>>>) :: (Functor f1, Functor f2, Functor f3) => f1 (a -> b) -> f1 (f2 (f3 a) -> f2 (f3 b)) -- (<<<$>>>) :: (Functor f1, Functor f2, Functor f3) => f1 (a -> b) -> f1 (f2 (f3 a) -> f2 (f3 b))
(<<<$>>>) :: (Functor f1, Functor f2, Functor f3) => (a -> b) -> f1 (f2 (f3 a)) -> f1 (f2 (f3 b)) (<<<$>>>) :: (Functor f1, Functor f2, Functor f3) => (a -> b) -> f1 (f2 (f3 a)) -> f1 (f2 (f3 b))
(<<<$>>>) = fmap fmap fmap fmap fmap fmap fmap fmap (<<<$>>>) = fmap fmap fmap fmap fmap fmap fmap fmap
ruleBody :: Text -> [Int] -> RuleBodyElement
ruleBody subRelationId indices =
RuleBodyElement
{ _subRelationId = subRelationId
, _ruleElements =
RuleElementVariable <$> indices
}