
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 an argument to 'replaceBasedIdxSub'. That means its value is fixed once you evaluate that function. Its value will not change no matter how many times the inner 'loop' function is evaluated. The solution is to pass the counter as an argument to said 'loop' function. Now when 'loop' enters the recursion you can pass a different value, such as counter + 1.
replaceBasedIdx :: String -> [String] -> String -> String replaceBasedIdx findStr replaceStrList myText = replaceBasedIdxSub findStr replaceStrList myText
replaceBasedIdxSub :: String -> [String] -> String -> String replaceBasedIdxSub findStr replaceStrList myText = loop 0 myText where loop :: Int -> String -> String loop counter [] = [] loop counter myText = let (prefix, rest) = splitAt n myText in if findStr == prefix then (replaceStrList !! counter) ++ loop (counter + 1) rest else head myText : loop counter (tail myText)
n :: Int n = length findStr