I have a recursive function which index a textile and if I use it for huge textfiles, i'll get a stack space overflow. I thought because I put the recursive part in the let part I could avoid this stack space overflow, but I'm still getting it. What would be the best way to avoid a stack space overflow with this function?
--lines to Map
parseLinesToWordEntryMap :: Int -> [String] -> M.Map Word [TextLocation] -> (M.Map Word [TextLocation])
parseLinesToWordEntryMap lineNumber [] wordEntryMap = wordEntryMap
parseLinesToWordEntryMap lineNumber (x:xs) wordEntryMap =
let
lineNumber' = lineNumber-1
wordEntryMapRec = parseLinesToWordEntryMap lineNumber' xs wordEntryMap
in
parseLineToWordEntryMap lineNumber x wordEntryMapRec
parseLineToWordEntryMap
– applicative Jul 9 '12 at 14:42