#3487: Data.ByteString.Lazy.elemIndices returns wrong results
-----------------------------+----------------------------------------------
Reporter:  nwn               |          Owner:                
    Type:  bug               |         Status:  new           
Priority:  normal            |      Component:  libraries/base
 Version:  6.10.4            |       Severity:  normal        
Keywords:                    |       Testcase:                
      Os:  Unknown/Multiple  |   Architecture:  x86           
-----------------------------+----------------------------------------------
 elemIndices for Lazy ByteString returns wrong results occasionally for
 huge input.

 {{{
 -- lei.hs
 import qualified Data.ByteString.Lazy as L
 import Control.Monad

 main = do
   n <- fmap (length . L.elemIndices 10) L.getContents
   putStrLn (show n)
 }}}

 {{{
 $ ghc --make lei
 [1 of 1] Compiling Main             ( lei.hs, lei.o )
 Linking lei ...
 $ yes | head -1000000 | ./lei
 1000000
 $ yes | head -1000000 | ./lei
 999992
 $ yes | head -1000000 | ./lei
 999960
 $ yes | head -1000000 | ./lei
 1000000
 $ yes | head -1000000 | ./lei
 999976
 }}}

 Without getContents, elemIndices works fine.

 {{{
 import qualified Data.ByteString.Lazy as L
 import System.Environment

 main = do
   n <- fmap (read . head) getArgs
   let cs = L.pack . take (2*n) . cycle $ [48,10]
       ps = L.elemIndices 10 cs
   print (length ps)
 }}}

 {{{
 $ ghc --make lei2.hs
 [1 of 1] Compiling Main             ( lei2.hs, lei2.o )
 Linking lei2 ...
 $ ./lei2 1000000
 1000000
 $ ./lei2 1000000
 1000000
 }}}

 So I think there is a problem about bytestring IO.

 And I heard this isn't reproduced in Windows' command prompt.

 This ticket is based on [http://www.sampou.org/cgi-bin/w3ml.cgi/haskell-
 jp/msg/381 a thread of haskell-jp].

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3487>
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