Rewrite type checking of patterns