+ Type[] parameterTypes = new Type[arity];
+ Type effect = Types.NO_EFFECTS;
+ int i;
+ for(i=0;i<arity;++i) {
+ if(type instanceof TFun) {
+ TFun fun = (TFun)type;
+ parameterTypes[i] = fun.getCanonicalDomain();
+ type = fun.getCanonicalRange();
+ effect = fun.getCanonicalEffect();
+ if(effect != Types.NO_EFFECTS) {
+ ++i;
+ break;
+ }
+ }
+ else if(type instanceof TMetaVar) {
+ Type domain = metaVar(Kinds.STAR);
+ parameterTypes[i] = domain;
+ Type range = metaVar(Kinds.STAR);
+ effect = metaVar(Kinds.EFFECT);
+ try {
+ ((TMetaVar) type).setRef(functionE(domain, effect, range));
+ } catch (UnificationException e) {
+ // Should never happen, if we have checked maximum arity before calling this function
+ throw new InternalCompilerError(e);
+ }
+ type = range;
+ ++i;
+ break;
+ }
+ else
+ break;
+ }
+
+ if(i < arity)
+ parameterTypes = Arrays.copyOf(parameterTypes, i);
+ return new MultiFunction(parameterTypes, effect, type);
+ }
+