Haskell has a RULES pragma that lets a user declare rewrites for the high-level optimizations that a compiler cannot deduce. They are most commonly used in the libraries. They are automatically applied by the compiler in the order of matching the AST from bottom-up.
``` {-# RULES
"map/map" forall f g xs. map f (map g xs) = map (f.g) xs
"map/append" forall f xs ys. map f (xs ++ ys) = map f xs ++ map f ys
#-}
```Depending on the order of rules application, the quality of optimization can differ a lot. This fragility makes it harder to understand the impact of even a minor code change on the performance. It is also very hard to test that a particular optimization is applied, and to track down why if it's not.