+
+ public static Type instantiateAndStrip(Type type) {
+ while(true) {
+ if(type instanceof TForAll) {
+ TForAll forAll = (TForAll)type;
+ type = forAll.type.replace(forAll.var, metaVar(forAll.var.getKind()));
+ }
+ else if(type instanceof TFun) {
+ TFun fun = (TFun)type;
+ if(fun.domain instanceof TPred || fun.domain == Types.PUNIT)
+ type = fun.range;
+ else
+ return type;
+ }
+ else if(type instanceof TMetaVar) {
+ TMetaVar metaVar = (TMetaVar)type;
+ if(metaVar.ref == null)
+ return type;
+ else
+ type = metaVar.ref;
+ }
+ else
+ return type;
+ }
+ }
+