@Test public void shouldNotUnifySumsWhenArgumentsDiffer() { SumType list1 = sum("List", asList(toType(Int.TYPE))); SumType list2 = sum("List", asList(toType(Bool.TYPE))); shouldBeMismatch(unify(list1, list2), toType(Int.TYPE), toType(Bool.TYPE)); }
public Unification unify(Type type, TypeScope scope) { return generate(scope).unify_(type.generate(scope), scope); }
Type { public Unification unify(Type type, TypeScope scope) { return generate(scope).unify_(type.generate(scope), scope); } }
Type { public Unification unify(Type type, TypeScope scope) { return generate(scope).unify_(type.generate(scope), scope); } Type(); }
Type { public Unification unify(Type type, TypeScope scope) { return generate(scope).unify_(type.generate(scope), scope); } Type(); abstract T accept(Visitor<T> visitor); HeadApplication apply(Type head, TypeScope scope); Unification apply(SumType head, List<Type> parameters, TypeScope scope); TailApplication apply(TailApplication application, TypeScope scope); HeadApplication applyWith(SumType type, TypeScope scope); Optional<List<Pair<Type,Type>>> applyZip(Pair<Type, Type> zippedPair, List<Type> parameters, TypeScope scope); HeadZip applyZipWith(SumType type, TypeScope scope); @Override abstract boolean equals(Object o); abstract Type flatten(); Type generate(TypeScope scope); abstract CodeBlock generateBytecode(); final Type genericCopy(TypeScope scope); Set<Symbol> getContext(); Set<Pair<VariableType, Symbol>> getContexts(); abstract Map<String, Type> getContexts(Type type, TypeScope scope); List<Pair<VariableType, Symbol>> getInstanceMap(); boolean hasContext(); @Override abstract int hashCode(); abstract Type mapVariables(Function<VariableType, Type> mapper); abstract Type qualifyNames(TypeQualifier qualifier); Type simplify(); abstract TypeDescriptor toDescriptor(); @Override String toString(); Unification unify(Type type, TypeScope scope); Optional<Map<Type, Type>> zip(Type other, TypeScope scope); }
Type { public Unification unify(Type type, TypeScope scope) { return generate(scope).unify_(type.generate(scope), scope); } Type(); abstract T accept(Visitor<T> visitor); HeadApplication apply(Type head, TypeScope scope); Unification apply(SumType head, List<Type> parameters, TypeScope scope); TailApplication apply(TailApplication application, TypeScope scope); HeadApplication applyWith(SumType type, TypeScope scope); Optional<List<Pair<Type,Type>>> applyZip(Pair<Type, Type> zippedPair, List<Type> parameters, TypeScope scope); HeadZip applyZipWith(SumType type, TypeScope scope); @Override abstract boolean equals(Object o); abstract Type flatten(); Type generate(TypeScope scope); abstract CodeBlock generateBytecode(); final Type genericCopy(TypeScope scope); Set<Symbol> getContext(); Set<Pair<VariableType, Symbol>> getContexts(); abstract Map<String, Type> getContexts(Type type, TypeScope scope); List<Pair<VariableType, Symbol>> getInstanceMap(); boolean hasContext(); @Override abstract int hashCode(); abstract Type mapVariables(Function<VariableType, Type> mapper); abstract Type qualifyNames(TypeQualifier qualifier); Type simplify(); abstract TypeDescriptor toDescriptor(); @Override String toString(); Unification unify(Type type, TypeScope scope); Optional<Map<Type, Type>> zip(Type other, TypeScope scope); static final Type NULL; }