Re: [Haskell-cafe] Incrementation fails

2013-05-08 Thread Roel van Dijk
> problem = replaceBasedIdx "X" ["b","d","f"] "aXcXeXgX" > -- "abcdefg*** Exception: Prelude.(!!): index too large This problem occurs because you never check if 'counter' is a valid index in the 'replaceStrList'. You can solve it by not using the !! operator at all. The solution is to also pass '

Re: [Haskell-cafe] Incrementation fails

2013-05-08 Thread Roel van Dijk
I stared at the code some more and deduced what I think is the intented meaning. Occurences of 'findStr' in 'myText' are replaced with the strings in 'replaceStrList'. So replaceBasedIdx "X" ["b","d","f"] "aXcXeXg" = "abcdefg" The reason your counter didn't increment is because it was defined as

Re: [Haskell-cafe] Incrementation fails

2013-05-08 Thread Roel van Dijk
Hi John, Can you tell us what your function is supposed to do? It appears to be some kind of search-and-replace for strings. What is the relationship between 'findStr', 'replaceStrList' and 'myText'? 2013/5/8 John > Hello All, > > I'm in a big trouble with incrementation of a counter in this c