public override bool IsSubtypeOf(CatKind k) { if (k.IsAny()) { return(true); } if (k is CatStackVar) { return(true); } if (!(k is CatTypeVector)) { return(false); } CatTypeVector v1 = this; CatTypeVector v2 = k as CatTypeVector; while (!v1.IsEmpty() && !v2.IsEmpty()) { CatKind t1 = v1.GetTop(); CatKind t2 = v2.GetTop(); if (!t1.IsSubtypeOf(t2)) { return(false); } v1 = v1.GetRest(); v2 = v2.GetRest(); } // v1 has to be at least as long to be a subtype if (v1.IsEmpty() && !v2.IsEmpty()) { return(false); } return(true); }
public override bool Equals(CatKind k) { if (!(k is CatTypeVector)) { return(false); } CatTypeVector v1 = this; CatTypeVector v2 = k as CatTypeVector; while (!v1.IsEmpty() && !v2.IsEmpty()) { CatKind t1 = v1.GetTop(); CatKind t2 = v2.GetTop(); if (!t1.Equals(t2)) { return(false); } v1 = v1.GetRest(); v2 = v2.GetRest(); } if (!v1.IsEmpty()) { return(false); } if (!v2.IsEmpty()) { return(false); } return(true); }