diff --git a/src/de/dhbwstuttgart/typeinference/unifynew/Unify.java b/src/de/dhbwstuttgart/typeinference/unifynew/Unify.java index 33943e85..d8354f53 100644 --- a/src/de/dhbwstuttgart/typeinference/unifynew/Unify.java +++ b/src/de/dhbwstuttgart/typeinference/unifynew/Unify.java @@ -54,13 +54,18 @@ public class Unify { List>> pairSetsSet = calculatePairSets(eq2s, fc); // The sets of the "first level" - Set> sets = new HashSet>(); - sets.add(eq1s); // Add Eq1' + Set> sets = new HashSet>(); + + if(eq1s.size() != 0) + sets.add(eq1s); // Add Eq1' // Add the set of [a =. Theta | (a=. Theta) in Eq2'] - sets.add(eq2s.stream() + Set bufferSet = eq2s.stream() .filter(x -> x.getPairOp() == PairOperator.EQUALSDOT && x.getLhsType() instanceof PlaceholderType) - .collect(Collectors.toSet())); + .collect(Collectors.toSet()); + + if(bufferSet.size() != 0) + sets.add(bufferSet); /* Up to here, no cartesian products are calculated. * Around here, filters for pairs and sets can be applied */ @@ -69,13 +74,19 @@ public class Unify { // Calculate the inner cartesian products // Cartesian products of the second level + + // AddAll -> nur add for(List> pairSets : pairSetsSet) // Prüfen ob addAll stimmt oder ob hier eigentlich nur 1 set sein sollte - setOps.cartesianProduct(pairSets).forEach(x -> sets.add(new HashSet(x))); + sets.add(setOps.cartesianProduct(pairSets).stream().map(x -> new HashSet<>(x)).collect(Collectors.toSet())); + + System.out.println(sets); // Calculate the outer cartesian products // Cartesian products of the first level - Set> eqsSet = setOps.cartesianProduct(new ArrayList<>(sets)); + Set> eqsSet = setOps.cartesianProduct(new ArrayList<>(sets)); + + System.out.println(eqsSet); /* * Step 5: Substitution */ @@ -90,7 +101,8 @@ public class Unify { * Step 7: Filter result for solved pairs */ - throw new NotImplementedException(); + return null; + } protected Set applyTypeUnificationRules(Set eq, IFiniteClosure fc) { diff --git a/test/unify/UnifyTest.java b/test/unify/UnifyTest.java index 65f94d96..38d5a1b9 100644 --- a/test/unify/UnifyTest.java +++ b/test/unify/UnifyTest.java @@ -25,12 +25,14 @@ public class UnifyTest extends Unify { IFiniteClosure fc = fcb.getCollectionExample(); // Vector <. Vector + // Vector // A <. Number // Double <. B // B <. Object eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Integer")), tf.getSimpleType("Vector", "A"), PairOperator.SMALLERDOT)); + eq.add(new MPair(tf.getSimpleType("Vector", tf.getSimpleType("Integer")), tf.getSimpleType("Vector", "C"), PairOperator.SMALLERDOT)); eq.add(new MPair(tf.getPlaceholderType("A"), tf.getSimpleType("Number"), PairOperator.SMALLERDOT)); - eq.add(new MPair(tf.getPlaceholderType("A"), tf.getPlaceholderType("C"), PairOperator.SMALLERDOT)); + //eq.add(new MPair(tf.getPlaceholderType("A"), tf.getPlaceholderType("C"), PairOperator.SMALLERDOT)); eq.add(new MPair(tf.getSimpleType("Double"), tf.getPlaceholderType("B"), PairOperator.SMALLERDOT)); eq.add(new MPair(tf.getPlaceholderType("B"), tf.getSimpleType("Object"), PairOperator.EQUALSDOT));