Low-order source
johanatan opened this issue · 1 comments
johanatan commented
Is there some reason that the source code for Roy is repetitious and has a low signal:noise ratio in many cases? For example, the following 3 functions from TypeInferrence.js are nearly identical and could be replaced with a single function parameterized on 'resultType' and appropriate calls to such.
visitBinaryNumberOperator: function() {
var resultType = new t.NumberType();
var leftType = analyse(node.left, env, nonGeneric, aliases, constraints);
var rightType = analyse(node.right, env, nonGeneric, aliases, constraints);
unify(leftType, resultType, node.left.lineno);
unify(rightType, resultType, node.right.lineno);
return resultType;
},
visitBinaryBooleanOperator: function() {
var resultType = new t.BooleanType();
var leftType = analyse(node.left, env, nonGeneric, aliases, constraints);
var rightType = analyse(node.right, env, nonGeneric, aliases, constraints);
unify(leftType, resultType, node.left.lineno);
unify(rightType, resultType, node.right.lineno);
return resultType;
},
visitBinaryStringOperator: function() {
var resultType = new t.StringType();
var leftType = analyse(node.left, env, nonGeneric, aliases, constraints);
var rightType = analyse(node.right, env, nonGeneric, aliases, constraints);
unify(leftType, resultType, node.left.lineno);
unify(rightType, resultType, node.right.lineno);
return resultType;
},
For a so-called 'functional' language, I expect its implementation to be more functional than this.
puffnfresh commented
Thanks for the code review. New type inference engine is being worked on in the constraints branch (see 904f611) - it suffers the same problem so a pull request would be appreciated there.