Rewrite rules can help with your program optimization. And I wonder if they would work if I wrap my objects in newtype
. As it's known, newtype
doesn't bring performance penalties, it's a compile-time wrapper which is gone at runtime. So I wonder if rewrite rules would still be triggered with newtype
. For example, there're a lot of rules for Data.Text
(What is fusion in Haskell?).
GHC user guide warns about non-smartness of algorithm:
GHC currently uses a very simple, syntactic, matching algorithm for matching a rule LHS with an expression. It seeks a substitution which makes the LHS and expression syntactically equal modulo alpha conversion. The pattern (rule), but not the expression, is eta-expanded if necessary. (Eta-expanding the expression can lead to laziness bugs.) But not beta conversion (that’s called higher-order matching).
And now I'm operating with Identity Text
(for some reasons). Would I still get those performance benefits? I'm not an expert in rewrite rules to perform benchmarks by myself and ensure in their results.