@@ -6,6 +6,7 @@ import qualified ProjectM36.DataConstructorDef as DCD
66import ProjectM36.MiscUtils
77import ProjectM36.Error
88import ProjectM36.DataTypes.Primitive
9+import ProjectM36.AttributeExpr as AE
910import qualified ProjectM36.Attribute as A
1011import qualified Data.Vector as V
1112import qualified Data.Set as S
@@ -55,6 +56,7 @@ isValidAtomTypeForTypeConstructor aType (PrimitiveTypeConstructor _ expectedATyp
5556--lookup constructor name and check if the incoming atom types are valid
5657isValidAtomTypeForTypeConstructor (ConstructedAtomType tConsName _) (ADTypeConstructor expectedTConsName _) _ = if tConsName /= expectedTConsName then Just (TypeConstructorNameMismatch expectedTConsName tConsName) else Nothing
5758
59+isValidAtomTypeForTypeConstructor (RelationAtomType attrs) (RelationAtomTypeConstructor attrExprs) _ = error "poopla"
5860isValidAtomTypeForTypeConstructor aType tCons _ = Just (AtomTypeTypeConstructorReconciliationError aType (TC.name tCons))
5961
6062-- | Used to determine if the atom arguments can be used with the data constructor.
@@ -116,17 +118,16 @@ resolveTypeConstructorTypeVars (ADTypeConstructor tConsName _) (ConstructedAtomT
116118 Left (TypeConstructorTypeVarsMismatch expectedPVarNames (M.keysSet pVarMap'))
117119resolveTypeConstructorTypeVars (TypeVariable tvName) typ _ = Right (M.singleton tvName typ)
118120resolveTypeConstructorTypeVars (ADTypeConstructor tConsName _) typ _ = Left (TypeConstructorAtomTypeMismatch tConsName typ)
119−resolveTypeConstructorTypeVars (RelationAtomTypeConstructor attrExpr) typ tConsMap =
121+resolveTypeConstructorTypeVars (RelationAtomTypeConstructor attrExprs) typ tConsMap =
120122 case typ of
121123 RelationAtomType attrs -> do
122− resolvedAttrs <- mapM (\atomtype' -> resolveAttributeExprTypeVars attrExpr atomtype' tConsMap) (map A.atomType (V.toList attrs))
123− error "poop"
124+ --resolve any typevars in the attrExprs
125+ error "poop4"
126+ otherType -> error "poop5"
124127
125128--used when recursing down sub-relation type definition
126129resolveAttributeExprTypeVars :: AttributeExprBase a -> AtomType -> TypeConstructorMapping -> Either RelationalError TypeVarMap
127−resolveAttributeExprTypeVars (NakedAttributeExpr attr) aType _ = do
128− resolvedType <- resolveAtomType (A.atomType attr) aType
129−
130+resolveAttributeExprTypeVars (NakedAttributeExpr attr) aType _ = error "poop2"
130131resolveAttributeExprTypeVars (AttributeAndTypeNameExpr _ tCons _) aType tConsMap = resolveTypeConstructorTypeVars tCons aType tConsMap
131132
132133-- check that type vars on the right also appear on the left
@@ -149,6 +150,10 @@ atomTypeForTypeConstructor (PrimitiveTypeConstructor _ aType) _ _ = Right aType
149150atomTypeForTypeConstructor (TypeVariable tvname) _ tvMap = case M.lookup tvname tvMap of
150151 Nothing -> Right (TypeVariableType tvname)
151152 Just typ -> Right typ
153+atomTypeForTypeConstructor (RelationAtomTypeConstructor attrExprs) tConsMap tvMap = do
154+ resolvedAtomTypes <- mapM (\expr -> atomTypeForAttributeExpr expr tConsMap tvMap) attrExprs
155+ let attrs = map (uncurry Attribute) (zip (map AE.attributeName attrExprs) resolvedAtomTypes)
156+ pure (RelationAtomType (A.attributesFromList attrs))
152157atomTypeForTypeConstructor tCons tConss tvMap = case findTypeConstructor (TC.name tCons) tConss of
153158 Nothing -> Left (NoSuchTypeConstructorError (TC.name tCons))
154159 Just (tConsDef, _) -> do
@@ -156,6 +161,10 @@ atomTypeForTypeConstructor tCons tConss tvMap = case findTypeConstructor (TC.nam
156161 let pVarNames = TCD.typeVars tConsDef
157162 tConsArgs = M.fromList (zip pVarNames tConsArgTypes)
158163 Right (ConstructedAtomType (TC.name tCons) tConsArgs)
164+
165+atomTypeForAttributeExpr :: AttributeExprBase a -> TypeConstructorMapping -> TypeVarMap -> Either RelationalError AtomType
166+atomTypeForAttributeExpr (NakedAttributeExpr attr) _ _ = pure (A.atomType attr)
167+atomTypeForAttributeExpr (AttributeAndTypeNameExpr _ tCons _) tConsMap tvMap = atomTypeForTypeConstructor tCons tConsMap tvMap
159168
160169findTypeConstructor :: TypeConstructorName -> TypeConstructorMapping -> Maybe (TypeConstructorDef, [DataConstructorDef])
161170findTypeConstructor name = foldr tConsFolder Nothing
@@ -228,7 +237,7 @@ validateAtomType typ@(ConstructedAtomType tConsName tVarMap) tConss =
228237 else
229238 Right ()
230239 _ -> Right ()
231−validateAtomType (RelationAtomType attrs) = error "poop"
240+validateAtomType (RelationAtomType attrs) _ = error "poop"
232241validateAtomType _ _ = Right ()
233242
234243validateTuple :: RelationTuple -> TypeConstructorMapping -> Either RelationalError ()