I'm having trouble writing this function that takes a character and a list of characters, then eliminates the last occurrence of that input character in the list. I was able to take out the first occurrence of the input character with my function below:
fun :: Char -> String -> String
fun c (s:ss)
| s == c = ss
| otherwise = s : fun c ss
fun _ [] = []
What I need help on is how I should modify this function to take out the last occurrence of the input character, instead of the first. The result should be something like fun 'c' "abcdccytrc"
returning "abcdccytr"
.