#2962: Reduce space usage of genericLength for common Num instances
---------------------------------+------------------------------------------
    Reporter:  thorkilnaur       |        Owner:  thorkilnaur     
        Type:  bug               |       Status:  new             
    Priority:  normal            |    Milestone:  6.12 branch     
   Component:  libraries/base    |      Version:  6.11            
    Severity:  normal            |   Resolution:                  
    Keywords:                    |   Difficulty:  Unknown         
    Testcase:                    |           Os:  Unknown/Multiple
Architecture:  Unknown/Multiple  |  
---------------------------------+------------------------------------------
Comment (by thorkilnaur):

 I attach a patch that adds rules for genericLength::[a]->Int and
 genericLength::[a]->Integer. Adding rules for Float and Double seems
 excessive, but it is of course easily done.

 That the result is as intended is witnessed by:
 {{{
 $ ghc-6.11.20090211 --version
 The Glorious Glasgow Haskell Compilation System, version 6.11.20090211
 $ cat R.hs
 import List
 import IO
 main = do hSetBuffering stdout NoBuffering
           print $ map ($ [1..4000000])
             [ genericLength :: [a] -> Int
             , fromIntegral . (genericLength :: [a] -> Integer)
             , round . (genericLength :: [a] -> Double)
             ]
 $ ghc-6.11.20090211 -fforce-recomp --make R -O
 [1 of 1] Compiling Main             ( R.hs, R.o )
 Linking R ...
 $ ./R
 [4000000,4000000,Stack space overflow: current size 8388608 bytes.
 Use `+RTS -Ksize' to increase it.
 $
 }}}
 Interestingly, this patch only solves the problem for compiled code. I
 don't know if it is possible to solve it for interpreted code also.

 Best regards
 Thorkil

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2962#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to