[Haskell-cafe] Diagnosing stack overflow

Justin Bailey jgbailey at gmail.com
Thu Aug 16 18:59:32 EDT 2007

I am trying to determine why my stack overflows in my medium sized
program (it has several modules but maybe only 1000 LOC total). On
Windows, at least, the ghcprof visualization tool doesn't work. Any
suggestions besides an output trace?

It may be the function below, which tries to determine if a list of
strict bytestrings is longer than the count given. I have tried to
make it strict but am not sure if it's too lazy. Any hints are

-- Determines if the length of the strings in the list is longer than the given
-- count. If not, amount the list falls short is returned. Otherwise,
-- -1 indicates the prefix list is at least that long. If the count is zero and
-- the list is empty or just null strings, -1 is also returned.
prefixesAtLeast :: Int -> [S.ByteString] -> Int
prefixesAtLeast !0 !ss
  | null ss = 0
  | all S.null ss = 0
  | otherwise = -1
prefixesAtLeast !n !ss = prefixesAtLeast' n ss
      prefixesAtLeast' !n ss
        | n < 0 = -1
        | null ss = n
        | otherwise =
            let (!s : (!rest)) = ss
              prefixesAtLeast' (n - (S.length s)) rest

More information about the Haskell-Cafe mailing list