@Test public void shouldAnalyzeMultiTypeClassExpression() { compile( "module scotch.test", "import scotch.data.eq", "import scotch.data.num", "fn a b = a + b == b + a" ); shouldNotHaveErrors(); Type bool = sum("scotch.data.bool.Bool"); Type t = t(18, asList("scotch.data.num.Num", "scotch.data.eq.Eq")); InstanceType numType = instance("scotch.data.num.Num", t(18)); InstanceType eqType = instance("scotch.data.eq.Eq", t(18)); shouldNotHaveErrors(); shouldHaveValue("scotch.test.fn", fn("scotch.test.(fn#0)", asList(arg("#0i", eqType), arg("#1i", numType), arg("#0", t), arg("#1", t)), scope("scotch.test.(fn#0#0)", let(bool, "a", arg("#0", t), let(bool, "b", arg("#1", t), apply( apply( apply( method("scotch.data.eq.(==)", asList(eqType), fn(eqType, fn(t, fn(t, bool)))), arg("#0i", eqType), fn(t, fn(t, bool)) ), apply( apply( apply( method("scotch.data.num.(+)", asList(numType), fn(numType, fn(t, fn(t, t)))), arg("#1i", numType), fn(t, fn(t, t)) ), arg("a", t), fn(t, t) ), arg("b", t), t ), fn(t, bool) ), apply( apply( apply( method("scotch.data.num.(+)", asList(numType), fn(numType, fn(t, fn(t, t)))), arg("#1i", numType), fn(t, fn(t, t)) ), arg("b", t), fn(t, t) ), arg("a", t), t ), bool )) )) )); }
public Scope scope() { return scopes.peek(); }
TypeChecker implements TypeScope { public Scope scope() { return scopes.peek(); } }
TypeChecker implements TypeScope { public Scope scope() { return scopes.peek(); } TypeChecker(DefinitionGraph graph); }
TypeChecker implements TypeScope { public Scope scope() { return scopes.peek(); } TypeChecker(DefinitionGraph graph); static SyntaxError ambiguousTypeInstance(Symbol typeClass, List<Type> parameters, Set<TypeInstanceDescriptor> typeInstances, SourceLocation location); static SyntaxError typeInstanceNotFound(Symbol typeClass, List<Type> parameters, SourceLocation location); void addLocal(Symbol symbol); Definition bind(ValueDefinition definition); @Override Unification bind(VariableType variableType, Type targetType); void capture(Symbol symbol); DefinitionGraph checkTypes(); Optional<DataTypeDescriptor> getDataType(Type type); Optional<DataConstructorDescriptor> getDataConstructor(Symbol symbol); T enclose(T scoped, Supplier<T> supplier); void error(SyntaxError error); @Override void extendContext(Type type, Set<Symbol> additionalContext); Optional<Value> findArgument(InstanceType type); Value findInstance(Method method, InstanceType instanceType); @Override void generalize(Type type); @Override Type generate(Type type); @Override Set<Symbol> getContext(Type type); Optional<Type> getDataConstructorType(Symbol constructor); Optional<Definition> getDefinition(DefinitionReference reference); Optional<Type> getRawValue(ValueReference valueRef); @Override Type getTarget(Type type); Type getType(ValueDefinition definition); @Override void implement(Symbol typeClass, SumType type); @Override boolean isBound(VariableType variableType); @Override boolean isGeneric(VariableType variableType); @Override boolean isImplemented(Symbol typeClass, SumType type); Definition keep(Definition definition); List<DefinitionReference> map(List<DefinitionReference> references, BiFunction<? super Definition, TypeChecker, ? extends Definition> function); void redefine(ValueDefinition definition); void redefine(ValueSignature signature); VariableType reserveType(); Scope scope(); T scoped(T scoped, Supplier<T> supplier); @Override void specialize(Type type); List<Value> bindMethods(List<Value> values); @SuppressWarnings("unchecked") List<T> bindTypes(List<T> values); List<Value> checkTypes(List<Value> values); }
TypeChecker implements TypeScope { public Scope scope() { return scopes.peek(); } TypeChecker(DefinitionGraph graph); static SyntaxError ambiguousTypeInstance(Symbol typeClass, List<Type> parameters, Set<TypeInstanceDescriptor> typeInstances, SourceLocation location); static SyntaxError typeInstanceNotFound(Symbol typeClass, List<Type> parameters, SourceLocation location); void addLocal(Symbol symbol); Definition bind(ValueDefinition definition); @Override Unification bind(VariableType variableType, Type targetType); void capture(Symbol symbol); DefinitionGraph checkTypes(); Optional<DataTypeDescriptor> getDataType(Type type); Optional<DataConstructorDescriptor> getDataConstructor(Symbol symbol); T enclose(T scoped, Supplier<T> supplier); void error(SyntaxError error); @Override void extendContext(Type type, Set<Symbol> additionalContext); Optional<Value> findArgument(InstanceType type); Value findInstance(Method method, InstanceType instanceType); @Override void generalize(Type type); @Override Type generate(Type type); @Override Set<Symbol> getContext(Type type); Optional<Type> getDataConstructorType(Symbol constructor); Optional<Definition> getDefinition(DefinitionReference reference); Optional<Type> getRawValue(ValueReference valueRef); @Override Type getTarget(Type type); Type getType(ValueDefinition definition); @Override void implement(Symbol typeClass, SumType type); @Override boolean isBound(VariableType variableType); @Override boolean isGeneric(VariableType variableType); @Override boolean isImplemented(Symbol typeClass, SumType type); Definition keep(Definition definition); List<DefinitionReference> map(List<DefinitionReference> references, BiFunction<? super Definition, TypeChecker, ? extends Definition> function); void redefine(ValueDefinition definition); void redefine(ValueSignature signature); VariableType reserveType(); Scope scope(); T scoped(T scoped, Supplier<T> supplier); @Override void specialize(Type type); List<Value> bindMethods(List<Value> values); @SuppressWarnings("unchecked") List<T> bindTypes(List<T> values); List<Value> checkTypes(List<Value> values);  }