simplified language features and tests
This commit is contained in:
parent
3003a92807
commit
05b6aefabe
@ -55,34 +55,36 @@ common warnings
|
|||||||
ghc-options: -Wall
|
ghc-options: -Wall
|
||||||
|
|
||||||
test-suite haskell-exps-test
|
test-suite haskell-exps-test
|
||||||
-- Import common warning flags.
|
-- Import common warning flags.
|
||||||
import: warnings
|
import: warnings
|
||||||
|
|
||||||
-- Base language which the package is written in.
|
-- Base language which the package is written in.
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
|
||||||
-- Modules included in this executable, other than Main.
|
-- Modules included in this executable, other than Main.
|
||||||
-- other-modules:
|
-- other-modules:
|
||||||
|
|
||||||
-- LANGUAGE extensions used by modules in this package.
|
-- LANGUAGE extensions used by modules in this package.
|
||||||
-- other-extensions:
|
-- other-extensions:
|
||||||
|
|
||||||
-- The interface type and version of the test suite.
|
-- The interface type and version of the test suite.
|
||||||
type: exitcode-stdio-1.0
|
type: exitcode-stdio-1.0
|
||||||
|
|
||||||
-- Directories containing source files.
|
-- Directories containing source files.
|
||||||
hs-source-dirs: test
|
hs-source-dirs: test
|
||||||
|
|
||||||
-- The entrypoint to the test suite.
|
-- The entrypoint to the test suite.
|
||||||
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
|
||||||
|
|
||||||
|
|||||||
BIN
haskell-experiments/notes/InMemoryDB_classes.png
Normal file
BIN
haskell-experiments/notes/InMemoryDB_classes.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 101 KiB |
@ -1,5 +1,3 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
|
||||||
|
|
||||||
module ArithmeticParser where
|
module ArithmeticParser where
|
||||||
|
|
||||||
import Text.Megaparsec
|
import Text.Megaparsec
|
||||||
|
|||||||
@ -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 #-}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
|
||||||
|
|
||||||
module Datalog.DatalogParser where
|
module Datalog.DatalogParser where
|
||||||
|
|
||||||
import Data.Void
|
import Data.Void
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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 #-}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
|
||||||
{-# LANGUAGE DuplicateRecordFields #-}
|
{-# LANGUAGE DuplicateRecordFields #-}
|
||||||
{-# LANGUAGE OverloadedRecordDot #-}
|
{-# LANGUAGE OverloadedRecordDot #-}
|
||||||
{-# HLINT ignore "Use const" #-}
|
{-# HLINT ignore "Use const" #-}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
{-# LANGUAGE OverloadedStrings #-}
|
|
||||||
{-# LANGUAGE DuplicateRecordFields #-}
|
{-# LANGUAGE DuplicateRecordFields #-}
|
||||||
{-# LANGUAGE OverloadedRecordDot #-}
|
{-# LANGUAGE OverloadedRecordDot #-}
|
||||||
{-# HLINT ignore "Use const" #-}
|
{-# HLINT ignore "Use const" #-}
|
||||||
|
|||||||
@ -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
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user