49 lines
1.5 KiB
Haskell
Raw Normal View History

2026-01-30 18:13:47 +00:00
{-# HLINT ignore "Redundant flip" #-}
2026-01-30 18:17:41 +00:00
-- {-# LANGUAGE ImportQualifiedPost #-}
-- {-# LANGUAGE InstanceSigs #-}
2026-01-30 18:13:47 +00:00
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# LANGUAGE BlockArguments #-}
2026-01-30 18:29:12 +00:00
{-# HLINT ignore "Redundant flip" #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE BlockArguments #-}
2026-01-30 18:13:47 +00:00
module Datalog.NaiveQE where
2026-01-30 18:29:12 +00:00
import Datalog.QueryEngine
import Data.Text
2026-02-03 11:03:46 +00:00
import Data.Map (Map)
import Data.Map qualified as Map
2026-01-30 18:29:12 +00:00
import Datalog.DatalogDB
import Datalog.DatalogParser
import Control.Exception
2026-02-03 11:03:46 +00:00
data (DatalogDB db) => NaiveQE db = NaiveQE
2026-01-30 18:29:12 +00:00
{
2026-02-03 11:03:46 +00:00
db :: db,
herbrand :: Map Text Relation
2026-01-30 18:29:12 +00:00
} deriving (Show, Eq)
instance QueryEngine NaiveQE where
2026-02-03 11:03:46 +00:00
queryEngine :: (DatalogDB db) => db -> NaiveQE db
2026-02-03 11:51:25 +00:00
queryEngine db = NaiveQE {
db = db,
herbrand = computeHerbrand db
}
2026-02-03 11:03:46 +00:00
query :: (DatalogDB db) => NaiveQE db -> Text -> Text
2026-01-30 18:29:12 +00:00
query qe queryText =
case parseDatalog queryText of
Right (Query texts literals) -> "#NYI"
Right otherStatement -> throw $ NonQueryException queryText otherStatement
Left ex -> throw $ CannotParseStatementException queryText ex
2026-02-03 11:51:25 +00:00
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) ->