Ineffective seq/BangPatterns
This could be related to #5557 (closed), but it might be something else.
- 2.1 was very picky about where you placed your bangs/seqs, for example
{-# LANGUAGE BangPatterns #-}
module Main (main) where
main :: IO ()
main = print (f 1000000)
f :: Integer -> Integer
f n = go n 0
where
go 0 !sm = sm
go k acc = go (k-1) (acc+k)
OR
module Main (main) where
main :: IO ()
main = print (f 1000000)
f :: Integer -> Integer
f n = go n 0
where
go a b | a `seq` b `seq` False = undefined
go k acc
| k == 0 = acc
| otherwise = go (k-1) (acc+k)
gave a stack overflow when compiled with ghc -O2. You have to place the bang/seq on the second equation for it to work. Older ghc versions treated it well, as does HEAD, so it seems fixed, but perhaps a regression test is in order?
Trac metadata
Trac field | Value |
---|---|
Version | 7.2.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |