function = apply(function, parameter);
return function;
}
-
- /**
- * Get the concrete type or alias type pointed to by a chain of type meta-variables,
- * or the last metavariable in the link, if it is not linked to an actual type.
- * Unlike {@link #canonical(Type)}, this method does not resolve type aliases.
- */
- public static Type weakCanonical(Type type) {
- while(true) {
- if(type instanceof TMetaVar) {
- TMetaVar metaVar = (TMetaVar)type;
- if(metaVar.ref == null)
- return type;
- else
- type = metaVar.ref;
- }
- else
- return type;
- }
- }
/**
- * Get the concrete type pointed to by a chain of type meta-variables. Unlike {@link #weakCanonical(Type)}
- * this method also resolves type aliases.
+ * Get the concrete type pointed to by a chain of type meta-variables.
*/
public static Type canonical(Type type) {
while(type instanceof TMetaVar) {
}
public static void unify(Type a, Type b) throws UnificationException {
- a = weakCanonical(a);
- b = weakCanonical(b);
+ a = canonical(a);
+ b = canonical(b);
if(a == b)
return;
if(a instanceof TMetaVar) {
e.getMessage()));
}
}
+
+ 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;
+ }
+ }
+
}