Simplify type-checking by matching