Conversation
|
For easy reference, here is the offending code fragment public TypeEnv addLetrecTypeBindings(TypeEnv tenv) {
List<String> stringVarList = new ArrayList<String>(varList.size());
for(Token t : varList) {
stringVarList.add(t.toString());
}
tenv = tenv.extendTypeEnv(new TypeBindings());
Iterator<Token> varIter = varList.iterator();
Iterator<Exp> expIter = expList.iterator();
while (varIter.hasNext()) {
String str = varIter.next().toString();
Exp e = expIter.next();
Type typ = null;
if (e instanceof ProcExp) {
typ = ((ProcExp) e).proc.definedType();
} else {
typ = e.evalType(tenv);
}
tenv.add(new TypeBinding(str, typ));
}
expIter = expList.iterator();
while (varIter.hasNext()) {
Type typ = expIter.next().evalType(tenv);
}
return tenv;
} |
|
Small comment first: I don’t see the point of stringVarList. It’s never used. |
|
PS I understand a need to go through twice. You’re trying to deal with mutual recursion. |
|
Reviewing the code in the file named "code” in TYPE1,, specifically the Proc class, I understand the dilemma. No quick answer revealed itself, of course. Will continue to think… |
@jashelio
@fosler
This pull-request attempts to allow mutual recursion in TYPE1's letrec.
I had to use an
instanceofin an if statement. I'm not happy with it. Should I add a new method to Exp that either returns the defined type for ProcExp or evaluates the expression for its type? Maybe call itevalTypeInLetrecDecl? Other suggestions?