2 weeks new to haskell and functional programming. In the process of covering foldl and foldr in class, I found that I was quite new to tail recursion and never actually tried writing a tail recursive function before (also new to how foldl traverses a list which is where it came up).
As an exercise, I tried to rewrite the following function to be tail recursive.
--replace replaces all instances of value x in a list with y
replace :: (Eq a) => a -> a -> [a] -> [a]
replace _ _ [] = []
replace x y (h:t) =
(if x==h then y: (replace x y t) else h: (replace x y t))
--tail recursive version of the same function
replacet _ _ [] = []
replacet x y (h:t) =
(if x==h then (replacet x y (y:t)) else (replacet x y (h:t)))
...But the output is just the following in ghci:
Nothing seems to be running at all, let alone getting an overflow.
Any ideas?

replacetin the first recursive call? What are the arguments toreplacetin the second recursive call?ghci>prompt to enter your next expression for evaluation.f x y t acc. Here,tis a list which will always decrease at each call, like the original program, while the result is slowly accumulated inacc(which can increase at each call). Initially thenreplacet x y t = f x y t []will provide the value foracc.