{-# LANGUAGE UnicodeSyntax #-}
module GraphRewriting.Pattern.Internal where

import GraphRewriting.Graph.Types
import Control.Monad.Reader
import Control.Monad.List


-- TODO: change the dependency of Match into a ReaderT Match?
-- | A pattern represents a graph scrutinisation that memorises all the scrutinised nodes during matching.
newtype PatternT n m a = PatternT {forall n (m :: * -> *) a.
PatternT n m a -> Match -> ReaderT (Graph n) (ListT m) (Match, a)
patternT  Match  ReaderT (Graph n) (ListT m) (Match, a)}

runPatternT'  Match  PatternT n m a  Graph n  m [(Match,a)]
runPatternT' :: forall n (m :: * -> *) a.
Match -> PatternT n m a -> Graph n -> m [(Match, a)]
runPatternT' Match
h PatternT n m a
p = forall (m :: * -> *) a. ListT m a -> m [a]
runListT forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (forall n (m :: * -> *) a.
PatternT n m a -> Match -> ReaderT (Graph n) (ListT m) (Match, a)
patternT PatternT n m a
p Match
h)

-- | Nodes matched in the evaluation of a pattern with the lastly matched node at the head
type Match = [Node]