[Haskell-cafe] lengthOP rewrite rules
Ryan Ingram
ryani.spam at gmail.com
Thu Dec 18 04:49:06 EST 2008
2008/12/18 Luke Palmer <lrpalmer at gmail.com>:
> 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...
I'm agreeing with Luke here. It's possible that the compiler decided
to inline f and i, and length, and determined that lf == 2000 and li
== _|_
Or it could have decided not to inline at all. Or some other possibility.
If you specify {-# INLINE lf #-}, do the results change? I suspect they might.
-- ryan
More information about the Haskell-Cafe
mailing list