on master help sign in
add relation atom type resolution
commit672d1035154f8de06be6649e086a9b450a4459f7 authorAgentM <agentm@themactionfaction.com> dateSat 7 Jul 2018, 00:25 (8 years ago) parent2b6470c
1 file changed+8−5
src/lib/ProjectM36/AtomType.hs+8−5
src/lib/ProjectM36/AtomType.hs+8−5
@@ -81,7 +81,7 @@ resolveDataConstructorTypeVars dCons@(DataConstructorDef _ defArgs) aTypeArgs tC
8181 --if any two maps have the same key and different values, this indicates a type arg mismatch
8282 let typeVarMapFolder valMap acc = case acc of
8383 Left err -> Left err
84− Right accMap -> do
84+ Right accMap ->
8585 case resolveAtomTypesInTypeVarMap valMap accMap of
8686 Left (TypeConstructorTypeVarMissing _) -> Left (DataConstructorTypeVarsMismatch (DCD.name dCons) accMap valMap)
8787 Left err -> Left err
@@ -254,6 +254,9 @@ resolveTypeInAtom typeFromRelation@(ConstructedAtomType _ tvMap) atomIn@(Constru
254254 atomArgTypes <- resolvedAtomTypesForDataConstructorDefArgs tConss tvMap dConsDef
255255 newArgs <- mapM (\(atom, atomTyp) -> resolveTypeInAtom atomTyp atom tConss) (zip args atomArgTypes)
256256 pure (ConstructedAtom dConsName newType newArgs)
257+resolveTypeInAtom (RelationAtomType attrs) (RelationAtom (Relation _ tupSet)) tConss = do
258+ let newTups = mapM (resolveTypesInTuple attrs tConss) (asList tupSet)
259+ RelationAtom . Relation attrs . RelationTupleSet <$> newTups
257260resolveTypeInAtom _ atom _ = Right atom
258261
259262-- | When creating a tuple, the data constructor may not complete the type constructor arguments, so the wildcard "TypeVar x" fills in the type constructor's argument. The tuple type must be resolved before it can be part of a relation, however.
@@ -286,17 +289,17 @@ validateAtomType _ _ = pure ()
286289
287290--ensure that all type vars are fully resolved
288291validateTypeVarMap :: TypeVarMap -> TypeConstructorMapping -> Either RelationalError ()
289−validateTypeVarMap tvMap tConss = mapM_ ((flip validateAtomType) tConss) $ (M.elems tvMap)
292+validateTypeVarMap tvMap tConss = mapM_ (`validateAtomType` tConss) $ M.elems tvMap
290293
291294validateTuple :: RelationTuple -> TypeConstructorMapping -> Either RelationalError ()
292−validateTuple (RelationTuple _ atoms) tConss = mapM_ (\a -> validateAtom a tConss) atoms
295+validateTuple (RelationTuple _ atoms) tConss = mapM_ (`validateAtom` tConss) atoms
293296
294297--ensure that all types are fully resolved
295298validateAtom :: Atom -> TypeConstructorMapping -> Either RelationalError ()
296−validateAtom (RelationAtom (Relation _ tupSet)) tConss = mapM_ ((flip validateTuple) tConss) (asList tupSet)
299+validateAtom (RelationAtom (Relation _ tupSet)) tConss = mapM_ (`validateTuple` tConss) (asList tupSet)
297300validateAtom (ConstructedAtom _ dConsType atomArgs) tConss = do
298301 validateAtomType dConsType tConss
299− mapM_ ((flip validateAtom) tConss) atomArgs
302+ mapM_ (`validateAtom` tConss) atomArgs
300303validateAtom _ _ = pure ()
301304
302305