Inference/src/TypeSystem/EquivalenceClass.cs
/// <summary>
/// Replaces the equivalence class substituting the old type variables for the new ones.
/// The substitution is not altered.
/// Since equivalence classes and type variables have a bidirectional association,
/// the new equivalence classes will make type variables update their new equivalence classes.
/// </summary>
/// <param name="typeVariableMappings">Each new type varaiable represent a copy of another existing one.
/// This parameter is a mapping between them, wher tmpName=old and value=new.</param>
Replaces the equivalence class substituting the old type variables for the new ones.
The substitution is not altered.
Since equivalence classes and type variables have a bidirectional association,
the new equivalence classes will make type variables update their new equivalence classes.
Replaces the equivalence class substituting the old type variables for the new ones . The substitution is not altered . Since equivalence classes and type variables have a bidirectional association the new equivalence classes will make type variables update their new equivalence classes .
public void UpdateEquivalenceClass(IDictionary<TypeVariable, TypeVariable> typeVariableMappings) {
            EquivalenceClass newEquivalenceClass = new EquivalenceClass();
            newEquivalenceClass.substitution = this.substitution;
            if (newEquivalenceClass.substitution != null)
                newEquivalenceClass.substitution.ReplaceTypeVariables(typeVariableMappings);
            newEquivalenceClass.typeVariables = new Dictionary<int, TypeVariable>();
            foreach (KeyValuePair<int, TypeVariable> oldPair in this.typeVariables) {
                if (typeVariableMappings.ContainsKey(oldPair.Value)) {
                    TypeVariable newTypeVariable = typeVariableMappings[oldPair.Value];
                    newEquivalenceClass.typeVariables[newTypeVariable.Variable] = newTypeVariable;
                    var previusSubstitution = newTypeVariable.Substitution;
                    newTypeVariable.EquivalenceClass = newEquivalenceClass;
                    if (previusSubstitution != null && newTypeVariable.Substitution == null)
                        newTypeVariable.EquivalenceClass.add(previusSubstitution, SortOfUnification.Equivalent, new List<Pair<TypeExpression, TypeExpression>>());
                    newTypeVariable.ValidTypeExpression = false;
                }
                else 
                    newEquivalenceClass.typeVariables[oldPair.Key] = oldPair.Value;
            }
            if (newEquivalenceClass.substitution != null)
                newEquivalenceClass.substitution.UpdateEquivalenceClass(typeVariableMappings, new List<TypeExpression>());
        }
public void UpdateEquivalenceClass ( IDictionary < TypeVariable , TypeVariable > typeVariableMappings ) { EquivalenceClass newEquivalenceClass = new EquivalenceClass ( ) ; newEquivalenceClass . substitution = this . substitution ; if ( newEquivalenceClass . substitution != null ) newEquivalenceClass . substitution . ReplaceTypeVariables ( typeVariableMappings ) ; newEquivalenceClass . typeVariables = new Dictionary < int , TypeVariable > ( ) ; foreach ( KeyValuePair < int , TypeVariable > oldPair in this . typeVariables ) { if ( typeVariableMappings . ContainsKey ( oldPair . Value ) ) { TypeVariable newTypeVariable = typeVariableMappings [ oldPair . Value ] ; newEquivalenceClass . typeVariables [ newTypeVariable . Variable ] = newTypeVariable ; var previusSubstitution = newTypeVariable . Substitution ; newTypeVariable . EquivalenceClass = newEquivalenceClass ; if ( previusSubstitution != null && newTypeVariable . Substitution == null ) newTypeVariable . EquivalenceClass . add ( previusSubstitution , SortOfUnification . Equivalent , new List < Pair < TypeExpression , TypeExpression > > ( ) ) ; newTypeVariable . ValidTypeExpression = false ; } else newEquivalenceClass . typeVariables [ oldPair . Key ] = oldPair . Value ; } if ( newEquivalenceClass . substitution != null ) newEquivalenceClass . substitution . UpdateEquivalenceClass ( typeVariableMappings , new List < TypeExpression > ( ) ) ; }
Replaces the equivalence class substituting the old type variables for the new ones.
Replaces the equivalence class substituting the old type variables for the new ones .
// * Creates a new equivalence class // * We take the existing substitution... //   ... changing old type variables for new ones // * We update all the appropiate type variables // * Is there a new type variable for the existing one? // * We create a new entry with the new one... // * ... and updates the class equivalence of the new type variable // * Otherwise, the old one is kept // * Finally, we update all the equivalence classes of the substitution if its exists
typeVariableMappings
IDictionary<TypeVariable, TypeVariable>
Each new type varaiable represent a copy of another existing one.
This parameter is a mapping between them, wher tmpName=old and value=new.
Each new type varaiable represent a copy of another existing one . This parameter is a mapping between them wher tmpName = old and value = new .