@Test public void shouldReplaceConstructorsWithSumsAsTheyAreInferenced() { scope.implement(symbol("Monad"), sum("Either", var("a"))); Type function = fn(ctor(t(9, asList("Monad")), t(10)), fn(fn(t(10), ctor(t(9, asList("Monad")), t(11))), ctor(t(9, asList("Monad")), t(11)))); Unification unification = fn(sum("Either", t(13), sum("Int")), t(6)).unify(function, scope); assertThat(unification.map(t -> unified(scope.generate(t))), is(unified( fn(sum("Either", t(13), sum("Int")), fn(fn(sum("Int"), sum("Either", t(13), t(11))), sum("Either", t(13), t(11)))) ))); }
@Override protected Type generate(TypeScope scope, Set<Type> visited) { return new ConstructorType(head.generate(scope, visited), tail.generate(scope, visited)).flatten(); }
ConstructorType extends Type { @Override protected Type generate(TypeScope scope, Set<Type> visited) { return new ConstructorType(head.generate(scope, visited), tail.generate(scope, visited)).flatten(); } }
ConstructorType extends Type { @Override protected Type generate(TypeScope scope, Set<Type> visited) { return new ConstructorType(head.generate(scope, visited), tail.generate(scope, visited)).flatten(); }  }
ConstructorType extends Type { @Override protected Type generate(TypeScope scope, Set<Type> visited) { return new ConstructorType(head.generate(scope, visited), tail.generate(scope, visited)).flatten(); }  @Override T accept(Visitor<T> visitor); @Override Type flatten(); @Override CodeBlock generateBytecode(); @Override Map<String, Type> getContexts(Type type, TypeScope scope); @Override Type mapVariables(Function<VariableType, Type> mapper); @Override Type qualifyNames(TypeQualifier qualifier); @Override TypeDescriptor toDescriptor(); }
ConstructorType extends Type { @Override protected Type generate(TypeScope scope, Set<Type> visited) { return new ConstructorType(head.generate(scope, visited), tail.generate(scope, visited)).flatten(); }  @Override T accept(Visitor<T> visitor); @Override Type flatten(); @Override CodeBlock generateBytecode(); @Override Map<String, Type> getContexts(Type type, TypeScope scope); @Override Type mapVariables(Function<VariableType, Type> mapper); @Override Type qualifyNames(TypeQualifier qualifier); @Override TypeDescriptor toDescriptor();  }