modified: ../../src/de/dhbwstuttgart/typeinference/unify/distributeVariance.java

Implementierung fuer FuNN eingefuegt
	deleted:    ../../src/de/dhbwstuttgart/typeinference/unify/inheritVariance.java

wahrscheinlich bei FuNN-Regeln Variance setzen.
This commit is contained in:
Martin Plümicke 2018-05-18 00:03:07 +02:00
parent 8baff8f376
commit d81c06cdd9
3 changed files with 33 additions and 22 deletions

View File

@ -25,7 +25,6 @@ import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
import de.dhbwstuttgart.typeinference.unify.RuleSet;
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
import de.dhbwstuttgart.typeinference.unify.distributeVariance;
import de.dhbwstuttgart.typeinference.unify.inheritVariance;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;

View File

@ -1,6 +1,14 @@
package de.dhbwstuttgart.typeinference.unify;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
public class distributeVariance extends visitUnifyTypeVisitor<Integer> {
@ -10,10 +18,32 @@ public class distributeVariance extends visitUnifyTypeVisitor<Integer> {
if (phty.getVariance() == 0) {
phty.setVariance(ht);
}
else if (phty.getVariance() != ht) {
phty.setVariance(0);
}
//PL 2018-05-17 urspruengliche Variance nicht veraendern
//else if (phty.getVariance() != ht) {
// phty.setVariance(0);
//}
}
return phty;
}
public FunNType visit(FunNType funnty, Integer ht) {
List<UnifyType> param = new ArrayList<>(funnty.getTypeParams().get().length);
param.addAll(Arrays.asList(funnty.getTypeParams().get()));
UnifyType resultType = param.remove(param.size()-1);
Integer htInverse = 0;
if (ht == 1) {
htInverse = -1;
}
if (ht == -1) {
htInverse = 1;
}
Integer htInverse1 = htInverse;
param = param.stream()
.map(x -> x.accept(this, htInverse1))
.collect(Collectors.toCollection(ArrayList::new));
param.add(resultType.accept(this, ht));
return FunNType.getFunNType(new TypeParams(param));
}
}

View File

@ -1,18 +0,0 @@
package de.dhbwstuttgart.typeinference.unify;
import java.util.HashMap;
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
public class inheritVariance extends visitUnifyTypeVisitor<HashMap<PlaceholderType,Integer>> {
@Override
public PlaceholderType visit(PlaceholderType phty, HashMap<PlaceholderType,Integer> ht) {
if (ht.containsKey(phty)) {
if (phty.getVariance() == 0) {
phty.setVariance(ht.get(phty));
}
}
return phty;
}
}