Rewrite type checking of lambdas