foldr/build seems to be broken
Reading the documentation for ghc it says that if a good consumer meets a good producer the intermediate list will disappear. List enumeration is s good producer, and length is a good consumer, so there should be no intermediate list between these.
Looking at the example below, it sure looks like a list is generated.
module CG1 where
foo :: Int -> Int
foo n = length [1..n]
-- Compile with
-- ghc -v5 -ddump-simpl-stats -ddump-rules -O2 -S CG1.hs
-- Output from this compilation
{-
Glasgow Haskell Compiler, Version 6.4.1, for Haskell 98, compiled by GHC version 6.4
....
==================== STG syntax: ====================
CG1.foo =
\r [n_s1Ah]
case n_s1Ah of wild1_s1Ap {
GHC.Base.I# y_s1Ak ->
case GHC.Enum.eftInt 1 y_s1Ak of sat_s1Am {
__DEFAULT ->
case GHC.List.$wlen sat_s1Am 0 of ww_s1Ao {
__DEFAULT -> GHC.Base.I# [ww_s1Ao];
};
};
};
SRT(CG1.foo): []
....
-}
Trac metadata
Trac field | Value |
---|---|
Version | 6.4.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | Unknown |
Architecture | Unknown |