Implement applyRewrite

applyRewrites takes a 'lhs ~> rhs` patch and a term and rewrites every matching
occurrence of 'lhs' in 'term' with 'applyPattern(rhs, env)'