initial setup for NaiveDatabase

This commit is contained in:
Felix Dilke 2026-01-21 11:24:30 +00:00
parent d31a01ab9c
commit 2900e781a1
6 changed files with 79 additions and 11 deletions

View File

@ -0,0 +1,26 @@
Copyright (c) 2025, Obsidian Systems
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -81,12 +81,13 @@ test-suite haskell-exps-test
other-modules: Test.OlogsSpec,
Test.SimpleParserSpec,
Test.ArithmeticParserSpec,
Test.Datalog.DatalogParserSpec
Test.Datalog.DatalogParserSpec,
Test.Datalog.NaiveDatabaseSpec
library langfeatures
build-depends: base, containers, megaparsec, parser-combinators, text
hs-source-dirs: src
exposed-modules: Ologs, SimpleParser, ArithmeticParser, Datalog.DatalogParser
exposed-modules: Ologs, SimpleParser, ArithmeticParser, Datalog.DatalogParser, Datalog.NaiveDatabase
ghc-options: -Wall
executable haskell-experiments

View File

@ -0,0 +1,18 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# HLINT ignore "Redundant flip" #-}
module Datalog.NaiveDatabase where
import Data.Map (Map)
import Data.Set (Set)
data Value =
ValueInt Int |
ValueSymbol String
data NaiveDatabase = NaiveDatabase {
relations :: Map String Int,
values :: Set Value
}

View File

@ -5,6 +5,7 @@ import qualified Test.OlogsSpec as Ologs
import qualified Test.SimpleParserSpec as SimpleParserSpec
import qualified Test.ArithmeticParserSpec as ArithmeticParserSpec
import qualified Test.Datalog.DatalogParserSpec as DatalogParserSpec
import qualified Test.Datalog.NaiveDatabaseSpec as NaiveDatabaseSpec
main :: IO ()
main = hspec $ do
@ -12,4 +13,5 @@ main = hspec $ do
describe "SimpleParser" SimpleParserSpec.spec
describe "ArithmeticParser" ArithmeticParserSpec.spec
describe "DatalogParser" DatalogParserSpec.spec
describe "NaiveDatabase" NaiveDatabaseSpec.spec

View File

@ -14,15 +14,6 @@ module Test.Datalog.DatalogParserSpec where
import Test.Hspec
import Datalog.DatalogParser
-- checkParse :: String -> Expr -> Expectation
-- checkParse text expectedExpr =
-- parse parseExpr "" text `shouldBe` Right expectedExpr
-- checkEval :: String -> Int -> Expectation
-- checkEval text expectedVal =
-- fmap eval (parse parseExpr "" text) `shouldBe` Right expectedVal
spec :: Spec
spec = do
describe "evaluate expressions" $ do

View File

@ -0,0 +1,30 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# HLINT ignore "Use const" #-}
{-# HLINT ignore "Unused LANGUAGE pragma" #-}
{-# HLINT ignore "Avoid lambda" #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE NoFieldSelectors #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# LANGUAGE TypeApplications #-}
module Test.Datalog.NaiveDatabaseSpec where
import Test.Hspec
import Datalog.NaiveDatabase
-- checkParse :: String -> Expr -> Expectation
-- checkParse text expectedExpr =
-- parse parseExpr "" text `shouldBe` Right expectedExpr
-- checkEval :: String -> Int -> Expectation
-- checkEval text expectedVal =
-- fmap eval (parse parseExpr "" text) `shouldBe` Right expectedVal
spec :: Spec
spec = do
describe "dummy test" $ do
it "..." $ do
1 `shouldBe` (1 :: Int)