public Type type(Env<String, Type> env) { Type t = op.type(env).deref(env); ast.types.Fun funType = Type.expect(op.getLineStart(), op.getLineEnd(), ast.types.Fun.class, this, t); checkArgTypes(funType, env); setType(funType.getRange()); return getType(); }
private void checkArgTypes(ast.types.Fun funType, Env<String, Type> env) { if (funType.getDomain().length == args.length) { for (int i = 0; i < funType.getDomain().length; i++) { Type suppliedType = args[i].type(env); Type expectedType = funType.getDomain()[i]; if (!Type.equals(expectedType, suppliedType, env)) { throw new TypeMatchError( getLineStart(), getLineEnd(), suppliedType, Type.eval(expectedType, env)); } } } else throw new TypeError( getLineStart(), getLineEnd(), "expecting " + funType.getDomain().length + " args but supplied with " + args.length); }