4 ms·
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
by lykahb 4y ago
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.
- ehatti 4y agoBecause of the nondeterminism we get from the metalanguage being a logic language, we don't have to worry about applying optimizers in a particular order. You can compose optimizers together, produce the possible results, and then select the best using a heuristic. Of course, the search space is potentially huge, so I'm looking into integrating constraints.