[Haskell-cafe] Strange behavior with listArray

Alex Stangl alex at stangl.us
Mon Nov 12 04:50:30 CET 2012


I'm stymied trying to figure out why the program below blows up with
<<<loop>>> when I use "f 0" for building the array, but if I substitute
g or h in place of f, they work fine. Is this a bug or am I overlooking
something? I am using GHC 7.4.2.

Thanks,

Alex

P.S. Forgive the seemingly pointless program; I distilled this test
from a longer actual program that was exhibiting this behavior.
--------

import Data.Array((!),Array,elems,listArray)
import Data.List(intercalate)

solve = let a :: Array Int Int
            a = listArray (0, 3) (0 : f 0)
            f k = if k > 0
                    then f (a!0)
                    else 0 : f 1
            g k = k : a!(k+1) : a!(k+1) : a!(k+2) : a!(k+3) : []
            h k = a!k : h (k+1)
        in (intercalate " " . map show . elems) a

main = putStrLn solve



More information about the Haskell-Cafe mailing list