@@ -18,7 +18,7 @@ import qualified ProjectM36.Attribute as A
18import qualified Data.Map as M
18import qualified Data.Map as M
19import qualified Data.HashSet as HS
19import qualified Data.HashSet as HS
20import qualified Data.Set as S
20import qualified Data.Set as S
21−import Control.Monad.Trans.RWS.Strict as RWS
21+import Control.Monad.RWS.Strict as RWS
22import Control.Monad.Trans.Class (lift)
22import Control.Monad.Trans.Class (lift)
23import Control.Exception
23import Control.Exception
24import Data.Maybe
24import Data.Maybe
@@ -27,8 +27,10 @@ import Data.Char (isUpper)
27import qualified Data.Text as T
27import qualified Data.Text as T
28import qualified Data.Vector as V
28import qualified Data.Vector as V
29import qualified ProjectM36.TypeConstructorDef as TCD
29import qualified ProjectM36.TypeConstructorDef as TCD
30−import Control.Monad.Trans.Except
30+import Control.Monad.Except
31+import Control.Monad.Trans.Except (except)
31−import Control.Monad.Trans.Reader as R
32+import Control.Monad.Reader as R
33+import ProjectM36.NormalizeExpr
32import Test.QuickCheck
34import Test.QuickCheck
34import GHC.Paths
36import GHC.Paths
@@ -38,6 +40,9 @@ import qualified Data.List.NonEmpty as NE
38import Data.Functor.Identity
40import Data.Functor.Identity
39import Control.Monad
41import Control.Monad
40import Control.Monad.IO.Class
42import Control.Monad.IO.Class
43+#if __GLASGOW_HASKELL__ <= 802
42data DatabaseContextExprDetails = CountUpdatedTuples
47data DatabaseContextExprDetails = CountUpdatedTuples
@@ -69,15 +74,35 @@ data RelationalExprEnv = RelationalExprEnv {
69 re_extra :: Maybe (Either RelationTuple Attributes)
74 re_extra :: Maybe (Either RelationTuple Attributes)
72−stateTuple :: RelationalExprEnv -> RelationTuple
77+envTuple :: GraphRefRelationalExprEnv -> RelationTuple
73−stateTuple e = fromLeft emptyTuple (fromMaybe (Left emptyTuple) (re_extra e))
78+envTuple e = fromLeft emptyTuple (fromMaybe (Left emptyTuple) (gre_extra e))
75−stateAttributes :: RelationalExprEnv -> Attributes
80+envAttributes :: GraphRefRelationalExprEnv -> Attributes
76−stateAttributes e = fromRight emptyAttributes (fromMaybe (Right emptyAttributes) (re_extra e))
81+envAttributes e = fromRight emptyAttributes (fromMaybe (Right emptyAttributes) (gre_extra e))
78instance Show RelationalExprEnv where
83instance Show RelationalExprEnv where
79 show e@RelationalExprEnv{} = "RelationalExprEnv " ++ show (re_extra e)
84 show e@RelationalExprEnv{} = "RelationalExprEnv " ++ show (re_extra e)
86+--used to eval relationalexpr
87+type RelationalExprM a = ReaderT RelationalExprEnv (ExceptT RelationalError Identity) a
89+reGraph :: RelationalExprM TransactionGraph
90+reGraph = re_graph <$> R.ask
92+gfTransForId :: TransactionId -> GraphRefRelationalExprM Transaction
95+ lift $ except $ transactionForId tid graph
97+currentTrans :: RelationalExprM Transaction
99+ tid <- re_currentTransId <$> R.ask
100+ graph <- re_graph <$> R.ask
101+ lift $ except $ transactionForId tid graph
103+reTransId :: RelationalExprM TransactionId
104+reTransId = re_currentTransId <$> R.ask
81mkRelationalExprEnv :: DatabaseContext -> TransactionId -> TransactionGraph -> RelationalExprEnv
106mkRelationalExprEnv :: DatabaseContext -> TransactionId -> TransactionGraph -> RelationalExprEnv
82mkRelationalExprEnv ctx currentTransId graph =
107mkRelationalExprEnv ctx currentTransId graph =
83 RelationalExprEnv
108 RelationalExprEnv
@@ -86,27 +111,21 @@ mkRelationalExprEnv ctx currentTransId graph =
86 re_currentTransId = currentTransId,
111 re_currentTransId = currentTransId,
87 re_extra = Nothing }
112 re_extra = Nothing }
89−askEnv :: RelationalExprState RelationalExprEnv
114+askEnv :: GraphRefRelationalExprM GraphRefRelationalExprEnv
90askEnv = R.ask
115askEnv = R.ask
92−currentTrans :: RelationalExprState (Either RelationalError Transaction)
117+mergeTuplesIntoGraphRefRelationalExprEnv :: RelationTuple -> GraphRefRelationalExprEnv -> GraphRefRelationalExprEnv
93−currentTrans = do
118+mergeTuplesIntoGraphRefRelationalExprEnv tupIn e =
94− tid <- re_currentTransId <$> R.ask
95− graph <- re_graph <$> R.ask
96− pure (transactionForId tid graph)
98−mergeTuplesIntoRelationalExprState :: RelationTuple -> RelationalExprEnv -> RelationalExprEnv
99−mergeTuplesIntoRelationalExprState tupIn e@RelationalExprEnv{} =
100− e{re_extra = new_elems }
119+ e{ gre_extra = new_elems }
102 new_elems = Just (Left newTuple)
121 new_elems = Just (Left newTuple)
103− mergedTupMap = M.union (tupleToMap tupIn) (tupleToMap (stateTuple e))
122+ mergedTupMap = M.union (tupleToMap tupIn) (tupleToMap (envTuple e))
104 newTuple = mkRelationTupleFromMap mergedTupMap
123 newTuple = mkRelationTupleFromMap mergedTupMap
106−mergeAttributesIntoRelationalExprState :: Attributes -> RelationalExprEnv -> RelationalExprEnv
125+mergeAttributesIntoGraphRefRelationalExprEnv :: Attributes -> GraphRefRelationalExprEnv -> GraphRefRelationalExprEnv
107−mergeAttributesIntoRelationalExprState attrsIn e@RelationalExprEnv{} = e{re_extra = newattrs }
126+mergeAttributesIntoGraphRefRelationalExprEnv attrsIn e = e { gre_extra = newattrs }
109− newattrs = Just (Right (A.union attrsIn (stateAttributes e)))
128+ newattrs = Just (Right (A.union attrsIn (envAttributes e)))
111type ResultAccumName = StringType
130type ResultAccumName = StringType
@@ -156,9 +175,25 @@ putStateContext ctx' = do
157 put (s {dbc_context = ctx'})
176 put (s {dbc_context = ctx'})
159−type RelationalExprState a = Reader RelationalExprEnv a
178+data GraphRefRelationalExprEnv =
179+ GraphRefRelationalExprEnv {
180+ gre_graph :: TransactionGraph,
181+ gre_extra :: Maybe (Either RelationTuple Attributes)
184+type GraphRefRelationalExprM a = ReaderT GraphRefRelationalExprEnv (ExceptT RelationalError Identity) a
186+runGraphRefRelationalExprM :: GraphRefRelationalExprEnv -> GraphRefRelationalExprM a -> Either RelationalError a
187+runGraphRefRelationalExprM env m = runIdentity (runExceptT (runReaderT m env))
189+freshGraphRefRelationalExprEnv :: TransactionGraph -> GraphRefRelationalExprEnv
190+freshGraphRefRelationalExprEnv graph = GraphRefRelationalExprEnv {
161−type GraphRefRelationalExprR a = Reader TransactionGraph a
195+gfGraph :: GraphRefRelationalExprM TransactionGraph
196+gfGraph = gre_graph <$> R.ask
163envContext :: RelationalExprEnv -> DatabaseContext
198envContext :: RelationalExprEnv -> DatabaseContext
164envContext = re_context
199envContext = re_context
@@ -354,12 +389,12 @@ evalGraphRefDatabaseContextExpr (Define relVarName attrExprs) = do
354 relvars <- fmap relationVariables getStateContext
389 relvars <- fmap relationVariables getStateContext
355 tConss <- fmap typeConstructorMapping getStateContext
390 tConss <- fmap typeConstructorMapping getStateContext
356 relEnv <- dbcRelationalExprEnv
391 relEnv <- dbcRelationalExprEnv
357− let eAttrs = runReader (mapM evalGraphRefAttrExpr attrExprs) relEnv
393+ let eAttrs = runGraphRefRelationalExprM gfEnv (mapM evalGraphRefAttrExpr attrExprs)
358− attrErrs = lefts eAttrs
394+ gfEnv = freshGraphRefRelationalExprEnv graph
359− attrsList = rights eAttrs
395+ case eAttrs of
360− if not (null attrErrs) then
396+ Left err -> dbErr err
361− dbErr (someErrors attrErrs)
397+ Right attrsList -> do
363 let atomTypeErrs = lefts $ map ((`validateAtomType` tConss) . A.atomType) attrsList
398 let atomTypeErrs = lefts $ map ((`validateAtomType` tConss) . A.atomType) attrsList
364 if not (null atomTypeErrs) then
399 if not (null atomTypeErrs) then
365 dbErr (someErrors atomTypeErrs)
400 dbErr (someErrors atomTypeErrs)
@@ -381,8 +416,9 @@ evalGraphRefDatabaseContextExpr (Assign relVarName expr) = do
381 Nothing -> do
416 Nothing -> do
382 setRelVar relVarName expr
417 setRelVar relVarName expr
383 Just existingRel -> do
418 Just existingRel -> do
384− let eExpectedType = runReader (typeForGraphRefRelationalExpr existingRel) graph
419+ let eExpectedType = runGraphRefRelationalExprM reEnv (typeForGraphRefRelationalExpr existingRel)
385− eNewExprType = runReader (typeForGraphRefRelationalExpr expr) graph
420+ eNewExprType = runGraphRefRelationalExprM reEnv (typeForGraphRefRelationalExpr expr)
421+ reEnv = freshGraphRefRelationalExprEnv graph
386 case eExpectedType of
422 case eExpectedType of
387 Left err -> dbErr err
423 Left err -> dbErr err
388 Right expectedType ->
424 Right expectedType ->
@@ -410,7 +446,7 @@ evalGraphRefDatabaseContextExpr (Delete relVarName predicate) = do
410evalGraphRefDatabaseContextExpr (Update relVarName atomExprMap pred') = do
446evalGraphRefDatabaseContextExpr (Update relVarName atomExprMap pred') = do
411 context <- getStateContext
447 context <- getStateContext
412 transId <- dbcTransId
448 transId <- dbcTransId
413− reEnv <- dbcRelationalExprEnv
449+ graph <- dbcGraph
414 let relVarMap = relationVariables context
450 let relVarMap = relationVariables context
415 case M.lookup relVarName relVarMap of
451 case M.lookup relVarName relVarMap of
416 Nothing -> dbErr (RelVarNotDefinedError relVarName)
452 Nothing -> dbErr (RelVarNotDefinedError relVarName)
@@ -422,7 +458,7 @@ evalGraphRefDatabaseContextExpr (Update relVarName atomExprMap pred') = do
422 projectAndRename attr expr = Rename (tmpAttr attr) attr (Project (InvertedAttributeNames (S.singleton attr)) expr)
458 projectAndRename attr expr = Rename (tmpAttr attr) attr (Project (InvertedAttributeNames (S.singleton attr)) expr)
423 restrictedPortion = Restrict pred'
459 restrictedPortion = Restrict pred'
424 updated = foldr (\(oldname, atomExpr) accum ->
460 updated = foldr (\(oldname, atomExpr) accum ->
425− let procAtomExpr = runReader (processAtomExpr atomExpr) reEnv in
461+ let procAtomExpr = runProcessExprM transId graph (processAtomExpr atomExpr) in
426 updateAttr oldname procAtomExpr accum
462 updateAttr oldname procAtomExpr accum
427 ) rv (M.toList atomExprMap)
463 ) rv (M.toList atomExprMap)
428 -- the atomExprMap could reference other attributes, so we must perform multi-pass folds
464 -- the atomExprMap could reference other attributes, so we must perform multi-pass folds
@@ -537,9 +573,11 @@ evalGraphRefDatabaseContextExpr (RemoveDatabaseContextFunction funcName) = do
537evalGraphRefDatabaseContextExpr (ExecuteDatabaseContextFunction funcName atomArgExprs) = do
573evalGraphRefDatabaseContextExpr (ExecuteDatabaseContextFunction funcName atomArgExprs) = do
538 context <- getStateContext
574 context <- getStateContext
539 relExprEnv <- dbcRelationalExprEnv
575 relExprEnv <- dbcRelationalExprEnv
540 --resolve atom arguments
577 --resolve atom arguments
541− let eAtomTypes = map (\atomExpr -> runReader (typeForGraphRefAtomExpr emptyAttributes atomExpr) relExprEnv) atomArgExprs
578+ let eAtomTypes = mapM (\atomExpr -> runGraphRefRelationalExprM gfEnv (typeForGraphRefAtomExpr emptyAttributes atomExpr)) atomArgExprs
542 eFunc = databaseContextFunctionForName funcName (dbcFunctions context)
579 eFunc = databaseContextFunctionForName funcName (dbcFunctions context)
580+ gfEnv = freshGraphRefRelationalExprEnv graph
543 case eFunc of
581 case eFunc of
544 Left err -> dbErr err
582 Left err -> dbErr err
545 Right func -> do
583 Right func -> do
@@ -549,10 +587,9 @@ evalGraphRefDatabaseContextExpr (ExecuteDatabaseContextFunction funcName atomArg
549 dbErr (FunctionArgumentCountMismatchError expectedArgCount actualArgCount)
587 dbErr (FunctionArgumentCountMismatchError expectedArgCount actualArgCount)
551 --check that the atom types are valid
589 --check that the atom types are valid
552− case lefts eAtomTypes of
590+ case eAtomTypes of
553− _:_ -> dbErr (someErrors (lefts eAtomTypes))
591+ Left err -> dbErr err
555− let atomTypes = rights eAtomTypes
592+ Right atomTypes -> do
556 let mValidTypes = map (\(expType, actType) -> case atomTypeVerify expType actType of
593 let mValidTypes = map (\(expType, actType) -> case atomTypeVerify expType actType of
557 Left err -> Just err
594 Left err -> Just err
558 Right _ -> Nothing) (zip (dbcFuncType func) atomTypes)
595 Right _ -> Nothing) (zip (dbcFuncType func) atomTypes)
@@ -711,36 +748,39 @@ evalGraphRefDatabaseContextIOExpr (CreateArbitraryRelation relVarName attrExprs
711 graph = dbcio_graph env
748 graph = dbcio_graph env
712 case runDatabaseContextEvalMonad currentContext evalEnv (evalGraphRefDatabaseContextExpr gfExpr) of
749 case runDatabaseContextEvalMonad currentContext evalEnv (evalGraphRefDatabaseContextExpr gfExpr) of
713 Left err -> pure (Left err)
750 Left err -> pure (Left err)
714− Right state -> do
751+ Right dbstate -> do
716 let existingRelVar = M.lookup relVarName relVarTable
753 let existingRelVar = M.lookup relVarName relVarTable
717− relVarTable = relationVariables (dbc_context state)
754+ relVarTable = relationVariables (dbc_context dbstate)
718 case existingRelVar of
755 case existingRelVar of
719 Nothing -> pure $ Left (RelVarNotDefinedError relVarName)
756 Nothing -> pure $ Left (RelVarNotDefinedError relVarName)
720 Just existingRel -> do
757 Just existingRel -> do
758+ let env = freshGraphRefRelationalExprEnv graph
721− case runReader (typeForGraphRefRelationalExpr existingRel) graph of
759+ case runGraphRefRelationalExprM env (typeForGraphRefRelationalExpr existingRel) of
722 Left err -> pure (Left err)
760 Left err -> pure (Left err)
723 Right relType -> do
761 Right relType -> do
724 let expectedAttributes = attributes relType
762 let expectedAttributes = attributes relType
725− tcMap = typeConstructorMapping (dbc_context state)
763+ tcMap = typeConstructorMapping (dbc_context dbstate)
726 eitherRel <- liftIO $ generate $ runReaderT (arbitraryRelation expectedAttributes range) tcMap
764 eitherRel <- liftIO $ generate $ runReaderT (arbitraryRelation expectedAttributes range) tcMap
727 case eitherRel of
765 case eitherRel of
728 Left err -> pure $ Left err
766 Left err -> pure $ Left err
729 Right rel ->
767 Right rel ->
730 case runDatabaseContextEvalMonad currentContext evalEnv (setRelVar relVarName (ExistingRelation rel)) of
768 case runDatabaseContextEvalMonad currentContext evalEnv (setRelVar relVarName (ExistingRelation rel)) of
731 Left err -> pure (Left err)
769 Left err -> pure (Left err)
732− Right state -> putDBCIOContext (dbc_context state)
770+ Right dbstate' -> putDBCIOContext (dbc_context dbstate')
734updateTupleWithAtomExprs :: M.Map AttributeName AtomExpr -> DatabaseContext -> TransactionGraph -> RelationTuple -> Either RelationalError RelationTuple
773updateTupleWithAtomExprs :: M.Map AttributeName AtomExpr -> DatabaseContext -> TransactionGraph -> RelationTuple -> Either RelationalError RelationTuple
735updateTupleWithAtomExprs exprMap context graph tupIn = do
774updateTupleWithAtomExprs exprMap context graph tupIn = do
736 --resolve all atom exprs
775 --resolve all atom exprs
737 atomsAssoc <- mapM (\(attrName, atomExpr) -> do
777 atomsAssoc <- mapM (\(attrName, atomExpr) -> do
738 let atom = unimplemented
778 let atom = unimplemented
739 --atom <- runReader (evalAtomExpr tupIn atomExpr) (mkRelationalExprState context graph)
779 --atom <- runReader (evalAtomExpr tupIn atomExpr) (mkRelationalExprState context graph)
740 pure (attrName, atom)
780 pure (attrName, atom)
741 ) (M.toList exprMap)
781 ) (M.toList exprMap)
742 pure (updateTupleWithAtoms (M.fromList atomsAssoc) tupIn)
782 pure (updateTupleWithAtoms (M.fromList atomsAssoc) tupIn)
744--run verification on all constraints
784--run verification on all constraints
745checkConstraints :: DatabaseContext -> TransactionId -> TransactionGraph -> Either RelationalError ()
785checkConstraints :: DatabaseContext -> TransactionId -> TransactionGraph -> Either RelationalError ()
746checkConstraints context transId graph@(TransactionGraph graphHeads transSet) =
786checkConstraints context transId graph@(TransactionGraph graphHeads transSet) =
@@ -756,14 +796,19 @@ checkConstraints context transId graph@(TransactionGraph graphHeads transSet) =
756 reEnv = mkRelationalExprEnv context transId graph
796 reEnv = mkRelationalExprEnv context transId graph
757 -- no optimization available here, really? perhaps the optimizer should be passed down to here or the eval function should be passed through the environment
797 -- no optimization available here, really? perhaps the optimizer should be passed down to here or the eval function should be passed through the environment
758 checkIncDep depName (InclusionDependency subsetExpr supersetExpr) = do
798 checkIncDep depName (InclusionDependency subsetExpr supersetExpr) = do
799+ let process = runProcessExprM transId graph
759− let gfSubsetExpr = runReader (processRelationalExpr subsetExpr) reEnv
800+ gfSubsetExpr = process (processRelationalExpr subsetExpr)
760− gfSupersetExpr = runReader (processRelationalExpr supersetExpr) reEnv
801+ gfSupersetExpr = process (processRelationalExpr supersetExpr)
761 --if both expressions are of a single-attribute (such as with a simple foreign key), the names of the attributes are irrelevant (they need not match) because the expression is unambiguous, but special-casing this to rename the attribute automatically would not be orthogonal behavior and probably cause confusion. Instead, special case the error to make it clear.
802 --if both expressions are of a single-attribute (such as with a simple foreign key), the names of the attributes are irrelevant (they need not match) because the expression is unambiguous, but special-casing this to rename the attribute automatically would not be orthogonal behavior and probably cause confusion. Instead, special case the error to make it clear.
762− typeSub <- runReader (typeForRelationalExpr subsetExpr) reEnv
803+ let gfEnv = freshGraphRefRelationalExprEnv graph
763− typeSuper <- runReader (typeForRelationalExpr supersetExpr) reEnv
804+ runGfRel = runGraphRefRelationalExprM gfEnv
805+ typeSub <- runGfRel (typeForGraphRefRelationalExpr gfSubsetExpr)
806+ typeSuper <- runGfRel (typeForGraphRefRelationalExpr gfSupersetExpr)
764 when (typeSub /= typeSuper) (Left (RelationTypeMismatchError (attributes typeSub) (attributes typeSuper)))
807 when (typeSub /= typeSuper) (Left (RelationTypeMismatchError (attributes typeSub) (attributes typeSuper)))
765 let checkExpr = Equals gfSupersetExpr (Union gfSubsetExpr gfSupersetExpr)
808 let checkExpr = Equals gfSupersetExpr (Union gfSubsetExpr gfSupersetExpr)
766− case evalGraphRefRelationalExpr checkExpr potentialGraph of
809+ gfEvald = runGraphRefRelationalExprM gfEnv (evalGraphRefRelationalExpr checkExpr)
810+ gfEnv = freshGraphRefRelationalExprEnv potentialGraph
767 Left err -> Left err
812 Left err -> Left err
768 Right resultRel -> if resultRel == relationTrue then
813 Right resultRel -> if resultRel == relationTrue then
@@ -773,13 +818,16 @@ checkConstraints context transId graph@(TransactionGraph graphHeads transSet) =
773-- the type of a relational expression is equal to the relation attribute set returned from executing the relational expression; therefore, the type can be cheaply derived by evaluating a relational expression and ignoring and tuple processing
818-- the type of a relational expression is equal to the relation attribute set returned from executing the relational expression; therefore, the type can be cheaply derived by evaluating a relational expression and ignoring and tuple processing
774-- furthermore, the type of a relational expression is the resultant header of the evaluated empty-tupled relation
819-- furthermore, the type of a relational expression is the resultant header of the evaluated empty-tupled relation
776−typeForRelationalExpr :: RelationalExpr -> RelationalExprState (Either RelationalError Relation)
821+typeForRelationalExpr :: RelationalExpr -> RelationalExprM Relation
777typeForRelationalExpr expr = do
822typeForRelationalExpr expr = do
778 --replace the relationVariables context element with a cloned set of relation devoid of tuples
823 --replace the relationVariables context element with a cloned set of relation devoid of tuples
779 --evalRelationalExpr could still return an existing relation with tuples, so strip them
824 --evalRelationalExpr could still return an existing relation with tuples, so strip them
826+ transId <- reTransId
780− gfExpr <- processRelationalExpr expr
827+ let gfExpr = runProcessExprM transId graph (processRelationalExpr expr)
781− graph <- re_graph <$> askEnv
828+ gfEnv = freshGraphRefRelationalExprEnv graph
782− pure $ runReader (typeForGraphRefRelationalExpr gfExpr) graph
829+ runGf = runGraphRefRelationalExprM gfEnv (typeForGraphRefRelationalExpr gfExpr)
830+ lift $ except $ runGf
784--returns a database context with all tuples removed
832--returns a database context with all tuples removed
785--this is useful for type checking and optimization
833--this is useful for type checking and optimization
@@ -794,67 +842,66 @@ liftE :: (Monad m) => m (Either a b) -> ExceptT a m b
794liftE v = do
842liftE v = do
795 y <- lift v
843 y <- lift v
796 case y of
844 case y of
797− Left err -> throwE err
845+ Left err -> throwError err
798 Right val -> pure val
846 Right val -> pure val
800{- used for restrictions- take the restrictionpredicate and return the corresponding filter function -}
848{- used for restrictions- take the restrictionpredicate and return the corresponding filter function -}
801−predicateRestrictionFilter :: Attributes -> RestrictionPredicateExprBase a -> RelationalExprState (Either RelationalError RestrictionFilter)
849+predicateRestrictionFilter :: Attributes -> GraphRefRestrictionPredicateExpr -> GraphRefRelationalExprM RestrictionFilter
802−predicateRestrictionFilter attrs (AndPredicate expr1 expr2) =
850+predicateRestrictionFilter attrs (AndPredicate expr1 expr2) = do
804− expr1v <- liftE (predicateRestrictionFilter attrs expr1)
851+ expr1v <- predicateRestrictionFilter attrs expr1
805− expr2v <- liftE (predicateRestrictionFilter attrs expr2)
852+ expr2v <- predicateRestrictionFilter attrs expr2
806− pure (\x -> do
853+ pure (\x -> do
807− ev1 <- expr1v x
854+ ev1 <- expr1v x
808− ev2 <- expr2v x
855+ ev2 <- expr2v x
809− pure (ev1 && ev2))
856+ pure (ev1 && ev2))
811−predicateRestrictionFilter attrs (OrPredicate expr1 expr2) =
858+predicateRestrictionFilter attrs (OrPredicate expr1 expr2) = do
813− expr1v <- liftE (predicateRestrictionFilter attrs expr1)
859+ expr1v <- predicateRestrictionFilter attrs expr1
814− expr2v <- liftE (predicateRestrictionFilter attrs expr2)
860+ expr2v <- predicateRestrictionFilter attrs expr2
815 pure (\x -> do
861 pure (\x -> do
816 ev1 <- expr1v x
862 ev1 <- expr1v x
817 ev2 <- expr2v x
863 ev2 <- expr2v x
818 pure (ev1 || ev2))
864 pure (ev1 || ev2))
820−predicateRestrictionFilter _ TruePredicate = pure (Right (\_ -> pure True))
866+predicateRestrictionFilter _ TruePredicate = pure (\_ -> pure True)
822−predicateRestrictionFilter attrs (NotPredicate expr) =
868+predicateRestrictionFilter attrs (NotPredicate expr) = do
824− exprv <- liftE (predicateRestrictionFilter attrs expr)
869+ exprv <- predicateRestrictionFilter attrs expr
825− pure (fmap not . exprv)
870+ pure (fmap not . exprv)
827--optimization opportunity: if the subexpression does not reference attributes in the top-level expression, then it need only be evaluated once, statically, outside the tuple filter- see historical implementation here
872--optimization opportunity: if the subexpression does not reference attributes in the top-level expression, then it need only be evaluated once, statically, outside the tuple filter- see historical implementation here
829predicateRestrictionFilter _ (RelationalExprPredicate relExpr) = do
873predicateRestrictionFilter _ (RelationalExprPredicate relExpr) = do
830− rstate <- ask
874+ renv <- askEnv
831− pure (Right (\tup -> case runReader (evalRelationalExpr relExpr) (mergeTuplesIntoRelationalExprState tup rstate) of
875+ let eval :: RelationTuple -> Either RelationalError Relation
877+ let gfEnv = mergeTuplesIntoGraphRefRelationalExprEnv tup renv in
878+ runGraphRefRelationalExprM gfEnv (evalGraphRefRelationalExpr relExpr)
879+ pure (\tup -> case eval tup of
832 Left err -> Left err
880 Left err -> Left err
833 Right rel -> if arity rel /= 0 then
881 Right rel -> if arity rel /= 0 then
834 Left (PredicateExpressionError "Relational restriction filter must evaluate to 'true' or 'false'")
882 Left (PredicateExpressionError "Relational restriction filter must evaluate to 'true' or 'false'")
836− pure (rel == relationTrue)))
884+ pure (rel == relationTrue))
838predicateRestrictionFilter attrs (AttributeEqualityPredicate attrName atomExpr) = do
886predicateRestrictionFilter attrs (AttributeEqualityPredicate attrName atomExpr) = do
839− rstate <- ask
887+ env <- askEnv
840− let attrs' = stateAttributes rstate
888+ let attrs' = envAttributes env
841− ctxtup' = stateTuple rstate
889+ ctxtup' = envTuple env
843− atomExprType <- liftE (typeFromAtomExpr attrs' atomExpr)
890+ atomExprType <- typeForGraphRefAtomExpr attrs' atomExpr
844− attr <- either throwE pure $ case A.attributeForName attrName attrs of
891+ attr <- lift $ except $ case A.attributeForName attrName attrs of
845 Right attr -> Right attr
892 Right attr -> Right attr
846 Left (NoSuchAttributeNamesError _) -> case A.attributeForName attrName (tupleAttributes ctxtup') of
893 Left (NoSuchAttributeNamesError _) -> case A.attributeForName attrName (tupleAttributes ctxtup') of
847 Right ctxattr -> Right ctxattr
894 Right ctxattr -> Right ctxattr
848 Left err2@(NoSuchAttributeNamesError _) -> Left err2
895 Left err2@(NoSuchAttributeNamesError _) -> Left err2
849 Left err -> Left err
896 Left err -> Left err
850 Left err -> Left err
897 Left err -> Left err
851− if atomExprType /= A.atomType attr then
898+ if atomExprType /= A.atomType attr then
852− throwE (TupleAttributeTypeMismatchError (A.attributesFromList [attr]))
899+ throwError (TupleAttributeTypeMismatchError (A.attributesFromList [attr]))
854 pure $ \tupleIn -> let evalAndCmp atomIn = case atomEvald of
901 pure $ \tupleIn -> let evalAndCmp atomIn = case atomEvald of
855 Right atomCmp -> atomCmp == atomIn
902 Right atomCmp -> atomCmp == atomIn
856 Left _ -> False
903 Left _ -> False
857− atomEvald = runReader (evalAtomExpr tupleIn atomExpr) rstate
904+ atomEvald = runGraphRefRelationalExprM env (evalGraphRefAtomExpr tupleIn atomExpr)
859 pure $ case atomForAttributeName attrName tupleIn of
906 pure $ case atomForAttributeName attrName tupleIn of
860 Left (NoSuchAttributeNamesError _) -> case atomForAttributeName attrName ctxtup' of
907 Left (NoSuchAttributeNamesError _) -> case atomForAttributeName attrName ctxtup' of
@@ -865,43 +912,44 @@ predicateRestrictionFilter attrs (AttributeEqualityPredicate attrName atomExpr)
865-- in the future, it would be useful to do typechecking on the attribute and atom expr filters in advance
912-- in the future, it would be useful to do typechecking on the attribute and atom expr filters in advance
866predicateRestrictionFilter attrs (AtomExprPredicate atomExpr) = do
913predicateRestrictionFilter attrs (AtomExprPredicate atomExpr) = do
867 --merge attrs into the state attributes
914 --merge attrs into the state attributes
868− rstate <- ask
915+ renv <- askEnv
870− aType <- liftE (typeFromAtomExpr attrs atomExpr)
916+ aType <- typeForGraphRefAtomExpr attrs atomExpr
871− if aType /= BoolAtomType then
917+ if aType /= BoolAtomType then
872− throwE (AtomTypeMismatchError aType BoolAtomType)
918+ throwError (AtomTypeMismatchError aType BoolAtomType)
874 pure (\tupleIn ->
920 pure (\tupleIn ->
875− case runReader (evalAtomExpr tupleIn atomExpr) rstate of
921+ case runGraphRefRelationalExprM renv (evalGraphRefAtomExpr tupleIn atomExpr) of
876− Left err -> Left err
922+ Left err -> Left err
877− Right boolAtomValue -> pure (boolAtomValue == BoolAtom True))
923+ Right boolAtomValue -> pure (boolAtomValue == BoolAtom True))
879tupleExprCheckNewAttrName :: AttributeName -> Relation -> Either RelationalError Relation
925tupleExprCheckNewAttrName :: AttributeName -> Relation -> Either RelationalError Relation
880tupleExprCheckNewAttrName attrName rel = if isRight (attributeForName attrName rel) then
926tupleExprCheckNewAttrName attrName rel = if isRight (attributeForName attrName rel) then
881 Left (AttributeNameInUseError attrName)
927 Left (AttributeNameInUseError attrName)
883 Right rel
929 Right rel
885−extendTupleExpressionProcessor :: Relation -> ExtendTupleExpr -> RelationalExprState (Either RelationalError (Attributes, RelationTuple -> Either RelationalError RelationTuple))
931+extendGraphRefTupleExpressionProcessor :: Relation -> GraphRefExtendTupleExpr -> GraphRefRelationalExprM (Attributes, RelationTuple -> Either RelationalError RelationTuple)
886−extendTupleExpressionProcessor relIn (AttributeExtendTupleExpr newAttrName atomExpr) = do
932+extendGraphRefTupleExpressionProcessor relIn (AttributeExtendTupleExpr newAttrName atomExpr) = do
887− rstate <- askEnv
933+ renv <- askEnv
888 -- check that the attribute name is not in use
934 -- check that the attribute name is not in use
889 case tupleExprCheckNewAttrName newAttrName relIn of
935 case tupleExprCheckNewAttrName newAttrName relIn of
890− Left err -> pure (Left err)
936+ Left err -> throwError err
891− Right _ -> runExceptT $ do
937+ Right _ -> do
892− atomExprType <- liftE (typeFromAtomExpr (attributes relIn) atomExpr)
938+ atomExprType <- typeForGraphRefAtomExpr (attributes relIn) atomExpr
893− atomExprType' <- liftE (verifyAtomExprTypes relIn atomExpr atomExprType)
939+ atomExprType' <- verifyGraphRefAtomExprTypes relIn atomExpr atomExprType
894 let newAttrs = A.attributesFromList [Attribute newAttrName atomExprType']
940 let newAttrs = A.attributesFromList [Attribute newAttrName atomExprType']
895 newAndOldAttrs = A.addAttributes (attributes relIn) newAttrs
941 newAndOldAttrs = A.addAttributes (attributes relIn) newAttrs
896− pure (newAndOldAttrs, \tup -> let substate = mergeTuplesIntoRelationalExprState tup rstate in
942+ pure (newAndOldAttrs, \tup -> let substate = mergeTuplesIntoGraphRefRelationalExprEnv tup renv in
897 case unimplemented {-runReader (evalAtomExpr tup atomExpr) substate-} of
943 case unimplemented {-runReader (evalAtomExpr tup atomExpr) substate-} of
898 Left err -> Left err
944 Left err -> Left err
899 Right atom -> Right (tupleAtomExtend newAttrName atom tup)
945 Right atom -> Right (tupleAtomExtend newAttrName atom tup)
948+evalGraphRefAtomExpr :: RelationTuple -> GraphRefAtomExpr -> GraphRefRelationalExprM Atom
949+evalGraphRefAtomExpr = unimplemented
903−evalAtomExpr :: RelationTuple -> AtomExpr -> RelationalExprState (Either RelationalError Atom)
951+evalAtomExpr :: RelationTuple -> AtomExpr -> RelationalExprM Atom
904−evalAtomExpr = undefined
952+evalAtomExpr = unimplemented
907evalAtomExpr tupIn (AttributeAtomExpr attrName) = case atomForAttributeName attrName tupIn of
955evalAtomExpr tupIn (AttributeAtomExpr attrName) = case atomForAttributeName attrName tupIn of
@@ -950,143 +998,129 @@ evalAtomExpr tupIn cons@(ConstructedAtomExpr dConsName dConsArgs ()) = runExcept
950 argAtoms <- mapM (\arg -> either throwE pure (runReader (evalAtomExpr tupIn arg) newState)) dConsArgs
998 argAtoms <- mapM (\arg -> either throwE pure (runReader (evalAtomExpr tupIn arg) newState)) dConsArgs
951 pure (ConstructedAtom dConsName aType argAtoms)
999 pure (ConstructedAtom dConsName aType argAtoms)
953−typeForGraphRefAtomExpr :: Attributes -> GraphRefAtomExpr -> RelationalExprState (Either RelationalError AtomType)
1001+typeForGraphRefAtomExpr :: Attributes -> GraphRefAtomExpr -> GraphRefRelationalExprM AtomType
954typeForGraphRefAtomExpr attrs (AttributeAtomExpr attrName) = do
1002typeForGraphRefAtomExpr attrs (AttributeAtomExpr attrName) = do
955− rstate <- askEnv
1003+ renv <- askEnv
956 case A.atomTypeForAttributeName attrName attrs of
1004 case A.atomTypeForAttributeName attrName attrs of
957− Right aType -> pure (Right aType)
1005+ Right aType -> pure aType
958 Left err@(NoSuchAttributeNamesError _) ->
1006 Left err@(NoSuchAttributeNamesError _) ->
959− let stateTup = stateTuple rstate
1007+ let envTup = envTuple renv
960− stateAttrs = stateAttributes rstate in
1008+ envAttrs = envAttributes renv in
961− case A.attributeForName attrName stateAttrs of
1009+ case A.attributeForName attrName envAttrs of
962− Right attr -> pure (Right (A.atomType attr))
1010+ Right attr -> pure (A.atomType attr)
963− Left _ -> case atomForAttributeName attrName stateTup of
1011+ Left _ -> case atomForAttributeName attrName envTup of
964− Right atom -> pure (Right (atomTypeForAtom atom))
1012+ Right atom -> pure (atomTypeForAtom atom)
965− Left _ -> pure (Left err)
1013+ Left _ -> throwError err
967−typeForGraphAtomExpr _ (NakedAtomExpr atom) = pure (Right (atomTypeForAtom atom))
1015+typeForGraphRefAtomExpr _ (NakedAtomExpr atom) = pure (atomTypeForAtom atom)
968−typeForGraphAtomExpr attrs (FunctionAtomExpr funcName atomArgs _) = do
1016+typeForGraphRefAtomExpr attrs (FunctionAtomExpr funcName atomArgs transId) = do
969− context <- fmap envContext askEnv
970− let funcs = atomFunctions context
1017+ funcs <- atomFunctions . concreteDatabaseContext <$> gfTransForId transId
971 case atomFunctionForName funcName funcs of
1018 case atomFunctionForName funcName funcs of
972− Left err -> pure (Left err)
1019+ Left err -> throwError err
973 Right func -> do
1020 Right func -> do
974 let funcRetType = last (atomFuncType func)
1021 let funcRetType = last (atomFuncType func)
975 funcArgTypes = init (atomFuncType func)
1022 funcArgTypes = init (atomFuncType func)
976− eArgTypes <- mapM (typeFromAtomExpr attrs) atomArgs
1023+ argTypes <- mapM (typeForGraphRefAtomExpr attrs) atomArgs
977− case lefts eArgTypes of
978− errs@(_:_) -> pure (Left (someErrors errs))
980− let eTvMap = resolveTypeVariables funcArgTypes argTypes
1024+ let eTvMap = resolveTypeVariables funcArgTypes argTypes
981− argTypes = rights eArgTypes
982− case eTvMap of
1025+ case eTvMap of
983− Left err -> pure (Left err)
1026+ Left err -> throwError err
984− Right tvMap -> pure (resolveFunctionReturnValue funcName tvMap funcRetType)
1027+ Right tvMap -> lift $ except $ resolveFunctionReturnValue funcName tvMap funcRetType
985−typeFromAtomExpr attrs (RelationAtomExpr relExpr) = do
1028+typeForGraphRefAtomExpr attrs (RelationAtomExpr relExpr) = do
986− relType <- R.local (mergeAttributesIntoRelationalExprState attrs) (typeForRelationalExpr relExpr)
1029+ relType <- R.local (mergeAttributesIntoGraphRefRelationalExprEnv attrs) (typeForGraphRefRelationalExpr relExpr)
988− Left err -> pure (Left err)
990− pure (pure (RelationAtomType (attributes relType')))
1030+ pure (RelationAtomType (attributes relType))
991-- grab the type of the data constructor, then validate that the args match the expected types
1031-- grab the type of the data constructor, then validate that the args match the expected types
992−typeFromAtomExpr attrs (ConstructedAtomExpr dConsName dConsArgs _) =
1032+typeForGraphRefAtomExpr attrs (ConstructedAtomExpr dConsName dConsArgs tid) =
993− runExceptT $ do
1033+ do
994− argsTypes <- mapM (liftE . typeFromAtomExpr attrs) dConsArgs
1034+ argsTypes <- mapM (typeForGraphRefAtomExpr attrs) dConsArgs
995− context <- fmap envContext (lift askEnv)
1035+ tConsMap <- typeConstructorMapping . concreteDatabaseContext <$> gfTransForId tid
996− either throwE pure (atomTypeForDataConstructor (typeConstructorMapping context) dConsName argsTypes)
1036+ lift $ except $ atomTypeForDataConstructor tConsMap dConsName argsTypes
998-- | Validate that the type of the AtomExpr matches the expected type.
1038-- | Validate that the type of the AtomExpr matches the expected type.
999−verifyAtomExprTypes :: Relation -> AtomExpr -> AtomType -> RelationalExprState (Either RelationalError AtomType)
1039+verifyGraphRefAtomExprTypes :: Relation -> GraphRefAtomExpr -> AtomType -> GraphRefRelationalExprM AtomType
1000−verifyAtomExprTypes relIn (AttributeAtomExpr attrName) expectedType = runExceptT $ do
1040+verifyGraphRefAtomExprTypes relIn (AttributeAtomExpr attrName) expectedType = do
1001− rstate <- lift askEnv
1041+ env <- askEnv
1002 case A.atomTypeForAttributeName attrName (attributes relIn) of
1042 case A.atomTypeForAttributeName attrName (attributes relIn) of
1003− Right aType -> either throwE pure (atomTypeVerify expectedType aType)
1043+ Right aType -> lift $ except $ atomTypeVerify expectedType aType
1004 (Left err@(NoSuchAttributeNamesError _)) ->
1044 (Left err@(NoSuchAttributeNamesError _)) ->
1005− let attrs' = stateAttributes rstate in
1045+ let attrs' = envAttributes env in
1006 if attrs' == emptyAttributes then
1046 if attrs' == emptyAttributes then
1007− throwE err
1047+ throwError err
1009 case A.attributeForName attrName attrs' of
1049 case A.attributeForName attrName attrs' of
1010− Left err' -> throwE err'
1050+ Left err' -> throwError err'
1011− Right attrType -> either throwE pure (atomTypeVerify expectedType (A.atomType attrType))
1051+ Right attrType -> lift $ except $ atomTypeVerify expectedType (A.atomType attrType)
1052+verifyGraphRefAtomExprTypes _ (NakedAtomExpr atom) expectedType =
1012−verifyAtomExprTypes _ (NakedAtomExpr atom) expectedType = pure (atomTypeVerify expectedType (atomTypeForAtom atom))
1053+ lift $ except $ atomTypeVerify expectedType (atomTypeForAtom atom)
1013−verifyAtomExprTypes relIn (FunctionAtomExpr funcName funcArgExprs _) expectedType = do
1054+verifyGraphRefAtomExprTypes relIn (FunctionAtomExpr funcName funcArgExprs tid) expectedType = do
1014− rstate <- askEnv
1055+ context <- concreteDatabaseContext <$> gfTransForId tid
1015 let functions = atomFunctions context
1056 let functions = atomFunctions context
1016− context = envContext rstate
1018− func <- either throwE pure (atomFunctionForName funcName functions)
1057+ func <- lift $ except $ atomFunctionForName funcName functions
1019− let expectedArgTypes = atomFuncType func
1058+ let expectedArgTypes = atomFuncType func
1020− funcArgTypes <- mapM (\(atomExpr,expectedType2,argCount) -> case runReader (verifyAtomExprTypes relIn atomExpr expectedType2) rstate of
1059+ funcArgVerifier (atomExpr, expectedType2, argCount) = do
1060+ let handler :: RelationalError -> GraphRefRelationalExprM AtomType
1021− Left (AtomTypeMismatchError expSubType actSubType) -> throwE (AtomFunctionTypeError funcName argCount expSubType actSubType)
1061+ handler (AtomTypeMismatchError expSubType actSubType) = throwError (AtomFunctionTypeError funcName argCount expSubType actSubType)
1022− Left err -> throwE err
1062+ handler err = throwError err
1023− Right x -> pure x
1063+ verifyGraphRefAtomExprTypes relIn atomExpr expectedType2 `catchError` handler
1024− ) $ zip3 funcArgExprs expectedArgTypes [1..]
1064+ funcArgTypes <- mapM funcArgVerifier $ zip3 funcArgExprs expectedArgTypes [1..]
1025− if length funcArgTypes /= length expectedArgTypes - 1 then
1065+ if length funcArgTypes /= length expectedArgTypes - 1 then
1026− throwE (AtomTypeCountError funcArgTypes expectedArgTypes)
1066+ throwError (AtomTypeCountError funcArgTypes expectedArgTypes)
1028− either throwE pure (atomTypeVerify expectedType (last expectedArgTypes))
1068+ lift $ except $ atomTypeVerify expectedType (last expectedArgTypes)
1029−verifyAtomExprTypes relIn (RelationAtomExpr relationExpr) expectedType = runExceptT $ do
1069+verifyGraphRefAtomExprTypes relIn (RelationAtomExpr relationExpr) expectedType =
1030− rstate <- lift askEnv
1070+ do
1031− relType <- either throwE pure (runReader (typeForRelationalExpr relationExpr) (mergeAttributesIntoRelationalExprState (attributes relIn) rstate))
1071+ let mergedAttrsEnv e = mergeAttributesIntoGraphRefRelationalExprEnv (attributes relIn) e
1072+ relType <- R.local mergedAttrsEnv (typeForGraphRefRelationalExpr relationExpr)
1032− either throwE pure (atomTypeVerify expectedType (RelationAtomType (attributes relType)))
1073+ lift $ except $ atomTypeVerify expectedType (RelationAtomType (attributes relType))
1033−verifyAtomExprTypes rel cons@ConstructedAtomExpr{} expectedType = runExceptT $ do
1074+verifyGraphRefAtomExprTypes rel cons@ConstructedAtomExpr{} expectedType = do
1034− cType <- liftE (typeFromAtomExpr (attributes rel) cons)
1075+ cType <- typeForGraphRefAtomExpr (attributes rel) cons
1035− either throwE pure (atomTypeVerify expectedType cType)
1076+ lift $ except $ atomTypeVerify expectedType cType
1037-- | Look up the type's name and create a new attribute.
1078-- | Look up the type's name and create a new attribute.
1038−evalGraphRefAttrExpr :: GraphRefAttributeExpr -> RelationalExprState (Either RelationalError Attribute)
1079+evalGraphRefAttrExpr :: GraphRefAttributeExpr -> GraphRefRelationalExprM Attribute
1039evalGraphRefAttrExpr (AttributeAndTypeNameExpr attrName tCons transId) = do
1080evalGraphRefAttrExpr (AttributeAndTypeNameExpr attrName tCons transId) = do
1040− graph <- re_graph <$> askEnv
1081+ tConsMap <- typeConstructorMapping . concreteDatabaseContext <$> gfTransForId transId
1041− case transactionForId transId graph of
1042− Left err -> pure (Left err)
1044− let tConsMap = typeConstructorMapping (concreteDatabaseContext trans)
1046− aType <- atomTypeForTypeConstructorValidate True tCons tConsMap M.empty
1082+ aType <- lift $ except $ atomTypeForTypeConstructorValidate True tCons tConsMap M.empty
1047− validateAtomType aType tConsMap
1083+ lift $ except $ validateAtomType aType tConsMap
1050− Left err -> pure (Left err)
1052− pure $ Right (Attribute attrName aType)
1084+ pure $ Attribute attrName aType
1054−evalGraphRefAttrExpr (NakedAttributeExpr attr) = pure $ Right attr
1086+evalGraphRefAttrExpr (NakedAttributeExpr attr) = pure attr
1056−evalTupleExpr :: Maybe Attributes -> TupleExpr -> RelationalExprState (Either RelationalError RelationTuple)
1088+evalGraphRefTupleExpr :: Maybe Attributes -> GraphRefTupleExpr -> GraphRefRelationalExprM RelationTuple
1057−evalTupleExpr mAttrs (TupleExpr tupMap) = do
1089+evalGraphRefTupleExpr mAttrs (TupleExpr tupMap) = do
1058− context <- fmap envContext askEnv
1060 -- it's not possible for AtomExprs in tuple constructors to reference other Attributes' atoms due to the necessary order-of-operations (need a tuple to pass to evalAtomExpr)- it may be possible with some refactoring of type usage or delayed evaluation- needs more thought, but not a priority
1090 -- it's not possible for AtomExprs in tuple constructors to reference other Attributes' atoms due to the necessary order-of-operations (need a tuple to pass to evalAtomExpr)- it may be possible with some refactoring of type usage or delayed evaluation- needs more thought, but not a priority
1061 -- I could adjust this logic so that when the attributes are not specified (Nothing), then I can attempt to extract the attributes from the tuple- the type resolution will blow up if an ambiguous data constructor is used (Left 4) and this should allow simple cases to "relation{tuple{a 4}}" to be processed
1091 -- I could adjust this logic so that when the attributes are not specified (Nothing), then I can attempt to extract the attributes from the tuple- the type resolution will blow up if an ambiguous data constructor is used (Left 4) and this should allow simple cases to "relation{tuple{a 4}}" to be processed
1062− let attrs = fromMaybe A.emptyAttributes mAttrs
1092+ let attrs = fromMaybe A.emptyAttributes mAttrs
1063− attrAtoms <- mapM (\(attrName, aExpr) -> do
1093+ resolveOneAtom (attrName, aExpr) =
1064− --provided when the relation header is available
1095+ --provided when the relation header is available
1065− let eExpectedAtomType = A.atomTypeForAttributeName attrName attrs
1096+ let eExpectedAtomType = A.atomTypeForAttributeName attrName attrs
1066− unresolvedType <- liftE (typeFromAtomExpr attrs aExpr)
1097+ unresolvedType <- typeForGraphRefAtomExpr attrs aExpr
1067− resolvedType <- case eExpectedAtomType of
1098+ resolvedType <- case eExpectedAtomType of
1068 Left _ -> pure unresolvedType
1099 Left _ -> pure unresolvedType
1069− Right typeHint -> either throwE pure (resolveAtomType typeHint unresolvedType)
1100+ Right typeHint -> lift $ except $ resolveAtomType typeHint unresolvedType
1070 --resolve atom typevars based on resolvedType?
1101 --resolve atom typevars based on resolvedType?
1071− newAtom <- liftE (evalAtomExpr emptyTuple aExpr)
1102+ newAtom <- evalGraphRefAtomExpr emptyTuple aExpr
1072− pure (attrName, newAtom, resolvedType)
1103+ pure (attrName, newAtom, resolvedType)
1073− ) (M.toList tupMap)
1104+ attrAtoms <- mapM resolveOneAtom (M.toList tupMap)
1074− let tupAttrs = A.attributesFromList $ map (\(attrName, _, aType) -> Attribute attrName aType) attrAtoms
1105+ let tupAttrs = A.attributesFromList $ map (\(attrName, _, aType) -> Attribute attrName aType) attrAtoms
1075− atoms = V.fromList $ map (\(_, atom, _) -> atom) attrAtoms
1106+ atoms = V.fromList $ map (\(_, atom, _) -> atom) attrAtoms
1076− tup = mkRelationTuple tupAttrs atoms
1107+ tup = mkRelationTuple tupAttrs atoms
1077− tConss = typeConstructorMapping context
1078− finalAttrs = fromMaybe tupAttrs mAttrs
1108+ finalAttrs = fromMaybe tupAttrs mAttrs
1079 --verify that the attributes match
1109 --verify that the attributes match
1080− when (A.attributeNameSet finalAttrs /= A.attributeNameSet tupAttrs) $ throwE (TupleAttributeTypeMismatchError tupAttrs)
1110+ when (A.attributeNameSet finalAttrs /= A.attributeNameSet tupAttrs) $ throwError (TupleAttributeTypeMismatchError tupAttrs)
1111+ --we can't resolve types here- they have to be resolved at the atom level where the graph ref is held
1081− tup' <- either throwE pure (resolveTypesInTuple finalAttrs tConss (reorderTuple finalAttrs tup))
1112+-- tup' <- lift $ except (resolveTypesInTuple finalAttrs tConss (reorderTuple finalAttrs tup))
1113+ let tup' = reorderTuple finalAttrs tup
1114+ --TODO: restore type resolution
1082− _ <- either throwE pure (validateTuple tup' tConss)
1115+-- _ <- lift $ except (validateTuple tup' tConss)
1083− pure tup'
1116+ pure tup'
1085−evalAttributeNames :: AttributeNames -> RelationalExpr -> RelationalExprState (Either RelationalError (S.Set AttributeName))
1119+evalAttributeNames :: AttributeNames -> RelationalExpr -> RelationalExprM (Either RelationalError (S.Set AttributeName))
1086evalAttributeNames attrNames expr = do
1120evalAttributeNames attrNames expr = do
1087 eExprType <- typeForRelationalExpr expr
1121 eExprType <- typeForRelationalExpr expr
1088 case eExprType of
1122 case eExprType of
1089− Left err -> pure (Left err)
1123+ Left err -> throwError err
1090 Right exprTyp -> do
1124 Right exprTyp -> do
1091 let typeNameSet = S.fromList (V.toList (A.attributeNames (attributes exprTyp)))
1125 let typeNameSet = S.fromList (V.toList (A.attributeNames (attributes exprTyp)))
1092 case attrNames of
1126 case attrNames of
@@ -1129,14 +1163,15 @@ evalAttributeNames attrNames expr = do
1129 case eAttrExprType of
1163 case eAttrExprType of
1130 Left err -> pure (Left err)
1164 Left err -> pure (Left err)
1131 Right attrExprType -> pure (Right (A.attributeNameSet (attributes attrExprType)))
1165 Right attrExprType -> pure (Right (A.attributeNameSet (attributes attrExprType)))
1133−evalGraphRefRelationalExpr :: GraphRefRelationalExpr -> TransactionGraph -> Either RelationalError Relation
1168+evalGraphRefRelationalExpr :: GraphRefRelationalExpr -> GraphRefRelationalExprM Relation
1134--evalGraphRefRelationalExpr (MakeRelationaFromExprs
1169--evalGraphRefRelationalExpr (MakeRelationaFromExprs
1135−evalGraphRefRelationalExpr (RelationVariable name tid) graph = do
1170+evalGraphRefRelationalExpr (RelationVariable name tid) = do
1136− ctx <- dbContextForTransId tid graph
1171+ ctx <- concreteDatabaseContext <$> gfTransForId tid
1137 case M.lookup name (relationVariables ctx) of
1172 case M.lookup name (relationVariables ctx) of
1138− Nothing -> Left (RelVarNotDefinedError name)
1173+ Nothing -> throwError (RelVarNotDefinedError name)
1139− Just rv -> evalGraphRefRelationalExpr rv graph
1174+ Just rv -> evalGraphRefRelationalExpr rv
1142dbContextForTransId :: TransactionId -> TransactionGraph -> Either RelationalError DatabaseContext
1177dbContextForTransId :: TransactionId -> TransactionGraph -> Either RelationalError DatabaseContext
@@ -1155,165 +1190,64 @@ transactionForId tid graph
1156 matchingTrans = S.filter (\(Transaction idMatch _ _) -> idMatch == tid) (transactionsForGraph graph)
1191 matchingTrans = S.filter (\(Transaction idMatch _ _) -> idMatch == tid) (transactionsForGraph graph)
1158−processRestrictionPredicateExpr :: RestrictionPredicateExpr -> RelationalExprState GraphRefRestrictionPredicateExpr
1159−processRestrictionPredicateExpr TruePredicate = pure TruePredicate
1160−processRestrictionPredicateExpr (AndPredicate a b) = AndPredicate <$> processRestrictionPredicateExpr a <*> processRestrictionPredicateExpr b
1161−processRestrictionPredicateExpr (OrPredicate a b) = OrPredicate <$> processRestrictionPredicateExpr a <*> processRestrictionPredicateExpr b
1162−processRestrictionPredicateExpr (NotPredicate a) = NotPredicate <$> processRestrictionPredicateExpr a
1163−processRestrictionPredicateExpr (RelationalExprPredicate expr) =
1164− RelationalExprPredicate <$> processRelationalExpr expr
1165−processRestrictionPredicateExpr (AtomExprPredicate expr) =
1166− AtomExprPredicate <$> processAtomExpr expr
1167−processRestrictionPredicateExpr (AttributeEqualityPredicate nam expr) =
1168− AttributeEqualityPredicate nam <$> processAtomExpr expr
1170−processExtendTupleExpr :: ExtendTupleExpr -> RelationalExprState GraphRefExtendTupleExpr
1171−processExtendTupleExpr (AttributeExtendTupleExpr nam atomExpr) =
1172− AttributeExtendTupleExpr nam <$> processAtomExpr atomExpr
1174−typeForGraphRefRelationalExpr :: GraphRefRelationalExpr -> GraphRefRelationalExprR (Either RelationalError Relation)
1193+typeForGraphRefRelationalExpr :: GraphRefRelationalExpr -> GraphRefRelationalExprM Relation
1175−typeForGraphRefRelationalExpr (MakeStaticRelation attrs _) = pure $ mkRelation attrs emptyTupleSet
1194+typeForGraphRefRelationalExpr (MakeStaticRelation attrs _) = lift $ except $ mkRelation attrs emptyTupleSet
1176−typeForGraphRefRelationalExpr (ExistingRelation rel) = pure (Right (emptyRelationWithAttrs (attributes rel)))
1195+typeForGraphRefRelationalExpr (ExistingRelation rel) = pure (emptyRelationWithAttrs (attributes rel))
1177typeForGraphRefRelationalExpr (MakeRelationFromExprs mAttrExprs tupleExprs) =
1196typeForGraphRefRelationalExpr (MakeRelationFromExprs mAttrExprs tupleExprs) =
1178 case mAttrExprs of
1197 case mAttrExprs of
1179 Just attrExprs -> do
1198 Just attrExprs -> do
1180− eAttrs <- mapM (\e -> evalGraphRefAttributeExpr e) attrExprs
1199+ attrs <- mapM (\e -> evalGraphRefAttributeExpr e) attrExprs
1181− case lefts eAttrs of
1182− [] -> pure (Right (emptyRelationWithAttrs (attributesFromList (rights eAttrs))))
1200+ pure (emptyRelationWithAttrs (attributesFromList attrs))
1183− _ -> pure (Left (someErrors (lefts eAttrs)))
1184typeForGraphRefRelationalExpr (RelationVariable rvName tid) = do
1201typeForGraphRefRelationalExpr (RelationVariable rvName tid) = do
1186− let eTrans = transactionForId tid graph
1188− Left err -> pure (Left err)
1190− let relVars = relationVariables (concreteDatabaseContext trans)
1202+ relVars <- relationVariables . concreteDatabaseContext <$> gfTransForId tid
1191− case M.lookup rvName relVars of
1203+ case M.lookup rvName relVars of
1192− Nothing -> pure (Left (RelVarNotDefinedError rvName))
1204+ Nothing -> throwError (RelVarNotDefinedError rvName)
1193− Just rvExpr -> typeForGraphRefRelationalExpr rvExpr
1205+ Just rvExpr -> typeForGraphRefRelationalExpr rvExpr
1194typeForGraphRefRelationalExpr (Project attrNames expr) = do
1206typeForGraphRefRelationalExpr (Project attrNames expr) = do
1195− eExprType <- typeForGraphRefRelationalExpr expr
1207+ exprType <- typeForGraphRefRelationalExpr expr
1197− Left err -> pure (Left err)
1198− Right exprType -> do
1199− eProjectionAttrs <- evalGraphRefAttributeNames attrNames expr
1208+ projectionAttrs <- evalGraphRefAttributeNames attrNames expr
1200− pure $ case eProjectionAttrs of
1201− Left err -> Left err
1202− Right projectionAttrs -> project projectionAttrs exprType
1209+ lift $ except $ project projectionAttrs exprType
1204−evalGraphRefAttributeNames :: GraphRefAttributeNames -> GraphRefRelationalExpr -> GraphRefRelationalExprR (Either RelationalError (S.Set AttributeName))
1211+evalGraphRefAttributeNames :: GraphRefAttributeNames -> GraphRefRelationalExpr -> GraphRefRelationalExprM (S.Set AttributeName)
1205evalGraphRefAttributeNames attrNames expr = do
1212evalGraphRefAttributeNames attrNames expr = do
1206− eExprType <- typeForGraphRefRelationalExpr expr
1213+ exprType <- typeForGraphRefRelationalExpr expr
1208− Left err -> pure (Left err)
1209− Right exprTyp -> do
1210− let typeNameSet = S.fromList (V.toList (A.attributeNames (attributes exprTyp)))
1214+ let typeNameSet = S.fromList (V.toList (A.attributeNames (attributes exprType)))
1211− case attrNames of
1215+ case attrNames of
1212− AttributeNames names ->
1216+ AttributeNames names ->
1213− case A.projectionAttributesForNames names (attributes exprTyp) of
1217+ case A.projectionAttributesForNames names (attributes exprType) of
1214− Left err -> pure (Left err)
1218+ Left err -> throwError err
1215− Right attrs -> pure (Right (S.fromList (V.toList (A.attributeNames attrs))))
1219+ Right attrs -> pure (S.fromList (V.toList (A.attributeNames attrs)))
1217− InvertedAttributeNames names -> do
1221+ InvertedAttributeNames names -> do
1218 let nonExistentAttributeNames = A.attributeNamesNotContained names typeNameSet
1222 let nonExistentAttributeNames = A.attributeNamesNotContained names typeNameSet
1219 if not (S.null nonExistentAttributeNames) then
1223 if not (S.null nonExistentAttributeNames) then
1220− pure (Left (AttributeNamesMismatchError nonExistentAttributeNames))
1224+ throwError (AttributeNamesMismatchError nonExistentAttributeNames)
1222− pure (pure (A.nonMatchingAttributeNameSet names typeNameSet))
1226+ pure (A.nonMatchingAttributeNameSet names typeNameSet)
1224− UnionAttributeNames namesA namesB -> do
1225− eNameSetA <- evalGraphRefAttributeNames namesA expr
1227− Left err -> pure (Left err)
1228− Right nameSetA -> do
1229− eNameSetB <- evalGraphRefAttributeNames namesB expr
1231− Left err -> pure (Left err)
1233− pure (Right (S.union nameSetA nameSetB))
1235− IntersectAttributeNames namesA namesB -> do
1228+ UnionAttributeNames namesA namesB -> do
1236− eNameSetA <- evalGraphRefAttributeNames namesA expr
1229+ nameSetA <- evalGraphRefAttributeNames namesA expr
1238− Left err -> pure (Left err)
1239− Right nameSetA -> do
1240− eNameSetB <- evalGraphRefAttributeNames namesB expr
1230+ nameSetB <- evalGraphRefAttributeNames namesB expr
1242− Left err -> pure (Left err)
1244− pure (Right (S.intersection nameSetA nameSetB))
1231+ pure (S.union nameSetA nameSetB)
1246− RelationalExprAttributeNames attrExpr -> do
1233+ IntersectAttributeNames namesA namesB -> do
1247− eAttrExprType <- typeForGraphRefRelationalExpr attrExpr
1234+ nameSetA <- evalGraphRefAttributeNames namesA expr
1248− case eAttrExprType of
1235+ nameSetB <- evalGraphRefAttributeNames namesB expr
1249− Left err -> pure (Left err)
1236+ pure (S.intersection nameSetA nameSetB)
1250− Right attrExprType -> pure (Right (A.attributeNameSet (attributes attrExprType)))
1238+ RelationalExprAttributeNames attrExpr -> do
1239+ attrExprType <- typeForGraphRefRelationalExpr attrExpr
1240+ pure (A.attributeNameSet (attributes attrExprType))
1255−processAtomExpr :: AtomExpr -> RelationalExprState GraphRefAtomExpr
1256−processAtomExpr (AttributeAtomExpr nam) = pure $ AttributeAtomExpr nam
1257−processAtomExpr (NakedAtomExpr atom) = pure $ NakedAtomExpr atom
1258−processAtomExpr (FunctionAtomExpr fName atomExprs ()) = do
1259− tid <- re_currentTransId <$> askEnv
1260− FunctionAtomExpr fName <$> mapM processAtomExpr atomExprs <*> pure tid
1261−processAtomExpr (RelationAtomExpr expr) = RelationAtomExpr <$> processRelationalExpr expr
1262−processAtomExpr (ConstructedAtomExpr dConsName atomExprs ()) = ConstructedAtomExpr dConsName <$> mapM processAtomExpr atomExprs <*> (re_currentTransId <$> askEnv)
1264−processTupleExpr :: TupleExpr -> RelationalExprState GraphRefTupleExpr
1265−processTupleExpr (TupleExpr tMap) =
1266− TupleExpr . M.fromList <$> mapM (\(k,v) -> (,) k <$> processAtomExpr v) (M.toList tMap)
1268−evalGraphRefAttributeExpr :: GraphRefAttributeExpr -> GraphRefRelationalExprR (Either RelationalError Attribute)
1242+evalGraphRefAttributeExpr :: GraphRefAttributeExpr -> GraphRefRelationalExprM Attribute
1269evalGraphRefAttributeExpr (AttributeAndTypeNameExpr attrName tCons tid) = do
1243evalGraphRefAttributeExpr (AttributeAndTypeNameExpr attrName tCons tid) = do
1271− case transactionForId tid graph of
1272− Left err -> pure (Left err)
1274− let tConsMap = typeConstructorMapping (concreteDatabaseContext trans)
1244+ tConsMap <- typeConstructorMapping . concreteDatabaseContext <$> gfTransForId tid
1275− case atomTypeForTypeConstructorValidate True tCons tConsMap M.empty of
1245+ case atomTypeForTypeConstructorValidate True tCons tConsMap M.empty of
1276− Left err -> pure (Left err)
1246+ Left err -> throwError err
1277− Right aType -> do
1247+ Right aType -> do
1278− case validateAtomType aType tConsMap of
1248+ case validateAtomType aType tConsMap of
1279− Left err -> pure (Left err)
1249+ Left err -> throwError err
1280− Right _ -> pure (Right (Attribute attrName aType))
1250+ Right _ -> pure (Attribute attrName aType)
1282−--convert AttributeExpr to GraphRefAttributeExpr
1283−processAttributeExpr :: AttributeExpr -> RelationalExprState GraphRefAttributeExpr
1284−processAttributeExpr (AttributeAndTypeNameExpr nam tCons ()) = do
1285− tid <- re_currentTransId <$> askEnv
1286− pure $ AttributeAndTypeNameExpr nam tCons tid
1287−processAttributeExpr (NakedAttributeExpr attr) = pure $ NakedAttributeExpr attr
1289−-- convert a RelationalExpr into a GraphRefRelationalExpr using the current trans Id
1290−-- can this be done without any RelationalErrors as opposed to evalRelationalExpr?
1291−processRelationalExpr :: RelationalExpr -> RelationalExprState GraphRefRelationalExpr
1292−processRelationalExpr (MakeRelationFromExprs mAttrs tupleExprs) = do
1293− mAttrs' <- case mAttrs of
1294− Nothing -> pure Nothing
1295− Just mAttrs'' -> Just <$> mapM processAttributeExpr mAttrs''
1296− MakeRelationFromExprs mAttrs' <$> mapM processTupleExpr tupleExprs
1297−processRelationalExpr (MakeStaticRelation attrs tupSet) = pure (MakeStaticRelation attrs tupSet)
1298−processRelationalExpr (ExistingRelation rel) = pure (ExistingRelation rel)
1299−processRelationalExpr (RelationVariable rv ()) = RelationVariable rv <$> fmap re_currentTransId askEnv
1300−processRelationalExpr (Project attrNames expr) = Project <$> processAttributeNames attrNames <*> processRelationalExpr expr
1301−processRelationalExpr (Union exprA exprB) = Union <$> processRelationalExpr exprA <*> processRelationalExpr exprB
1302−processRelationalExpr (Join exprA exprB) = Join <$> processRelationalExpr exprA <*> processRelationalExpr exprB
1303−processRelationalExpr (Rename attrA attrB expr) =
1304− Rename attrA attrB <$> processRelationalExpr expr
1305−processRelationalExpr (Difference exprA exprB) = Difference <$> processRelationalExpr exprA <*> processRelationalExpr exprB
1306−processRelationalExpr (Group attrNames attrName expr) = Group <$> processAttributeNames attrNames <*> pure attrName <*> processRelationalExpr expr
1307−processRelationalExpr (Ungroup attrName expr) = Ungroup attrName <$> processRelationalExpr expr
1308−processRelationalExpr (Restrict pred expr) = Restrict <$> processRestrictionPredicateExpr pred <*> processRelationalExpr expr
1309−processRelationalExpr (Equals exprA exprB) =
1310− Equals <$> processRelationalExpr exprA <*> processRelationalExpr exprB
1311−processRelationalExpr (NotEquals exprA exprB) =
1312− NotEquals <$> processRelationalExpr exprA <*> processRelationalExpr exprB
1313−processRelationalExpr (Extend extendExpr expr) =
1314− Extend <$> processExtendTupleExpr extendExpr <*> processRelationalExpr expr
1315−processRelationalExpr (With macros expr) =
1316− With <$> mapM (\(nam, wexpr) -> (,) nam <$> processRelationalExpr wexpr) macros <*> processRelationalExpr expr
1318mkEmptyRelVars :: RelationVariables -> RelationVariables
1252mkEmptyRelVars :: RelationVariables -> RelationVariables
1319mkEmptyRelVars rvMap = M.map mkEmptyRelVar rvMap
1253mkEmptyRelVars rvMap = M.map mkEmptyRelVar rvMap
@@ -1335,50 +1269,10 @@ mkEmptyRelVars rvMap = M.map mkEmptyRelVar rvMap
1335 mkEmptyRelVar (Extend extTuple expr) = Extend extTuple (mkEmptyRelVar expr)
1269 mkEmptyRelVar (Extend extTuple expr) = Extend extTuple (mkEmptyRelVar expr)
1336 mkEmptyRelVar (With macros expr) = With (map (\(rv, expr) -> (rv, mkEmptyRelVar expr)) macros) (mkEmptyRelVar expr)
1270 mkEmptyRelVar (With macros expr) = With (map (\(rv, expr) -> (rv, mkEmptyRelVar expr)) macros) (mkEmptyRelVar expr)
1338−processAttributeNames :: AttributeNames -> RelationalExprState GraphRefAttributeNames
1339−processAttributeNames (AttributeNames nameSet) = pure $ AttributeNames nameSet
1340−processAttributeNames (UnionAttributeNames attrNamesA attrNamesB) = UnionAttributeNames <$> processAttributeNames attrNamesA <*> processAttributeNames attrNamesB
1341−processAttributeNames (IntersectAttributeNames attrNamesA attrNamesB) = IntersectAttributeNames <$> processAttributeNames attrNamesA <*> processAttributeNames attrNamesB
1342−processAttributeNames (RelationalExprAttributeNames expr) = RelationalExprAttributeNames <$> processRelationalExpr expr
1344−processDatabaseContextExpr :: DatabaseContextExpr -> RelationalExprState GraphRefDatabaseContextExpr
1345−processDatabaseContextExpr expr =
1347− NoOperation -> pure NoOperation
1348− Define nam attrExprs -> Define nam <$> mapM processAttributeExpr attrExprs
1349− Undefine nam -> pure (Undefine nam)
1350− Assign nam rexpr -> Assign nam <$> processRelationalExpr rexpr
1351− Insert nam rexpr -> Insert nam <$> processRelationalExpr rexpr
1352− Delete nam pred -> Delete nam <$> processRestrictionPredicateExpr pred
1353− Update nam attrMap pred -> Update nam attrMap <$> processRestrictionPredicateExpr pred
1355− AddInclusionDependency nam dep -> pure (AddInclusionDependency nam dep)
1356− RemoveInclusionDependency nam -> pure (RemoveInclusionDependency nam)
1357− AddNotification nam exprA exprB exprC -> pure (AddNotification nam exprA exprB exprC)
1358− RemoveNotification nam -> pure (RemoveNotification nam)
1359− AddTypeConstructor tyDef consDefs -> pure (AddTypeConstructor tyDef consDefs)
1360− RemoveTypeConstructor tyName -> pure (RemoveTypeConstructor tyName)
1362− RemoveAtomFunction aFuncName -> pure (RemoveAtomFunction aFuncName)
1363− RemoveDatabaseContextFunction funcName -> pure (RemoveDatabaseContextFunction funcName)
1364− ExecuteDatabaseContextFunction funcName atomExprs -> ExecuteDatabaseContextFunction funcName <$> mapM processAtomExpr atomExprs
1365− MultipleExpr exprs -> MultipleExpr <$> mapM processDatabaseContextExpr exprs
1367dbErr :: RelationalError -> DatabaseContextEvalMonad ()
1273dbErr :: RelationalError -> DatabaseContextEvalMonad ()
1368dbErr err = lift (except (Left err))
1274dbErr err = lift (except (Left err))
1370−processDatabaseContextIOExpr :: DatabaseContextIOExpr -> RelationalExprState GraphRefDatabaseContextIOExpr
1371−processDatabaseContextIOExpr (AddAtomFunction f tcs sc) =
1372− pure (AddAtomFunction f tcs sc)
1373−processDatabaseContextIOExpr (LoadAtomFunctions mod fun file) =
1374− pure (LoadAtomFunctions mod fun file)
1375−processDatabaseContextIOExpr (AddDatabaseContextFunction mod fun path) =
1376− pure (AddDatabaseContextFunction mod fun path)
1377−processDatabaseContextIOExpr (LoadDatabaseContextFunctions mod fun path) =
1378− pure (LoadDatabaseContextFunctions mod fun path)
1379−processDatabaseContextIOExpr (CreateArbitraryRelation rvName attrExprs range) =
1380− CreateArbitraryRelation rvName <$> mapM processAttributeExpr attrExprs <*> pure range
1382-- | Return a Relation describing the relation variables.
1276-- | Return a Relation describing the relation variables.
1383relationVariablesAsRelation :: RelationVariables -> TransactionGraph -> Either RelationalError Relation
1277relationVariablesAsRelation :: RelationVariables -> TransactionGraph -> Either RelationalError Relation
1384relationVariablesAsRelation relVarMap graph = do
1278relationVariablesAsRelation relVarMap graph = do
@@ -1386,7 +1280,8 @@ relationVariablesAsRelation relVarMap graph = do
1386 attrs = A.attributesFromList [Attribute "name" TextAtomType,
1280 attrs = A.attributesFromList [Attribute "name" TextAtomType,
1387 Attribute "attributes" (RelationAtomType subrelAttrs)]
1281 Attribute "attributes" (RelationAtomType subrelAttrs)]
1388 mkRvDesc (rvName, gfExpr) = do
1282 mkRvDesc (rvName, gfExpr) = do
1283+ let gfEnv = freshGraphRefRelationalExprEnv graph
1389− gfType <- runReader (typeForGraphRefRelationalExpr gfExpr) graph
1284+ gfType <- runGraphRefRelationalExprM gfEnv (typeForGraphRefRelationalExpr gfExpr)
1390 pure (rvName, gfType)
1285 pure (rvName, gfType)
1391 relVarToAtomList (rvName, rel) = [TextAtom rvName, attributesToRel (attributes rel)]
1286 relVarToAtomList (rvName, rel) = [TextAtom rvName, attributesToRel (attributes rel)]
1392 attrAtoms a = [TextAtom (A.attributeName a), TextAtom (prettyAtomType (A.atomType a))]
1287 attrAtoms a = [TextAtom (A.attributeName a), TextAtom (prettyAtomType (A.atomType a))]