[Haskell-cafe] lengthOP rewrite rules

Luke Palmer lrpalmer at gmail.com
Thu Dec 18 04:18:33 EST 2008

On Thu, Dec 18, 2008 at 1:53 AM, Cetin Sert <cetin.sert at gmail.com> wrote:
> Hi,
> I tested the following, why does the rewrite rules not fire when using
tuples also in testRewrite2, testRewriteReverse2?

testRewrite2 :: a → (Bool,Bool)
> testRewrite2 x = (pf,pi)
>   where
>     f  = replicate 2000 x
>     i  = repeat         x
>     lf = length f
>     li = length i
>     pf = lf > 300
>     pi = li > 300
Why would you expect it to?  The compiler is free to inline lf and li to
discover that the rule applies, but it is also free not to.  Applying all
applicable rules while maintaining the ability to abstract is undecidable
(big surprise). Thus the dependency on compiler cleverness I mentioned...

There might be something you can do with rule ordering, make sure it happens
after the inlining phase, but I don't know how to do that offhand.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081218/34b599a0/attachment.htm

More information about the Haskell-Cafe mailing list