/* function types for tiger */ /* Chuck Liang */ package Types; public class FUNC extends Type { public tlist domain; // parameter types public Type range; // return type FUNC(tlist d, Type r) { domain = d; range = r; } public boolean coerceTo(Type ti) { if (!(ti.actual() instanceof FUNC))return false; FUNC t = (FUNC) ti; return (coerceDomain(t.domain) && coerceRange(t.range)); } public boolean coerceDomain(tlist args) // compare parameter types { if (args.length() != domain.length()) return false; boolean answer = true; tlist current1 = domain; tlist current2 = args; while (current1 != null) { answer = answer && (current1.head.coerceTo(current2.head)); current1 = current1.tail; current2 = current2.tail; } return answer; } public boolean coerceRange(Type t) // compare return type { return range.coerceTo(t); } }// end of class FUNC