2026-02-03 11:51:25 +00:00

49 lines
1.5 KiB
Haskell

{-# HLINT ignore "Redundant flip" #-}
-- {-# LANGUAGE ImportQualifiedPost #-}
-- {-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# LANGUAGE BlockArguments #-}
{-# HLINT ignore "Redundant flip" #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE BlockArguments #-}
module Datalog.NaiveQE where
import Datalog.QueryEngine
import Data.Text
import Data.Map (Map)
import Data.Map qualified as Map
import Datalog.DatalogDB
import Datalog.DatalogParser
import Control.Exception
data (DatalogDB db) => NaiveQE db = NaiveQE
{
db :: db,
herbrand :: Map Text Relation
} deriving (Show, Eq)
instance QueryEngine NaiveQE where
queryEngine :: (DatalogDB db) => db -> NaiveQE db
queryEngine db = NaiveQE {
db = db,
herbrand = computeHerbrand db
}
query :: (DatalogDB db) => NaiveQE db -> Text -> Text
query qe queryText =
case parseDatalog queryText of
Right (Query texts literals) -> "#NYI"
Right otherStatement -> throw $ NonQueryException queryText otherStatement
Left ex -> throw $ CannotParseStatementException queryText ex
computeHerbrand :: (DatalogDB db) => db -> Map Text Relation
computeHerbrand db =
computeHerbrandSub Map.empty where
computeHerbrandSub :: Map Text Relation -> Map Text Relation
computeHerbrandSub facts = facts
-- for_ (Map.toList myMap) $ \(k,v) ->