There is no such thing as "forward recursion". Tail recursion defines a special kind of recursion, that occurs in a tail position. When you want to refer to a recursion that is not in a tail position, you call it "non tail recursive"
In the code you've specified there is no recursion at all. So, I would suggest you first of all to try to write remove_if
function and try to figure out whether it is tail or non-tail.
Update
I usually try no to solve homework for others, but at this case I will give a little kick start, by providing you with the most common definition of remove_if
function:
let rec remove matches = function
| [] -> []
| x :: xs when matches x -> remove matches xs
| x :: xs -> x :: remove matches xs
There are two occurrences of recursion in this function:
| x :: xs when matches x -> remove matches xs
^^^^^^^^^^^^^^^^^
last expression -
tail recursion
| x :: xs -> x :: remove matches xs
^^^^^^^^^^^^^^^^^
not the last -
non tail recursive
So, last case needs some clarification: before the x
can be prepended to the result of remove matches xs
the latter expression needs to be evaluated. That means that computer needs to store x
somewhere, to wait until remove matches xs
is evaluatd.
So, no the fun part, you have a non-tail recursive version. Now, try to implement it tail recursively. Have fun
!