How can I propagate information backwards in a recursive call-chain?
For example:
f :: [Int] -> [Int]
f (x:xs)
| x `mod` 17 = ...
| otherwise = (x + 1) : f xs
f [] = []
I want to stop the evaluation at the ..., and I also want to propagate that information back to the caller (the fact that it stopped). I tried to use return types like Maybe, but then I had to pattern-match the recursive call, and thus lost tail-call optimization, since I had to evaluate it after the call returned (note: one could easily transform the above code to TR form, but I left it like this for easier understanding).
Can you come up with a better solution that still benefits from TCO?