Generally you shouldn't use recursion unless you actually need it, but just to answer the specific question here, the type of a coroutine is IEnumerator. So you can use
function foo() : IEnumerator
to fix the error message, though using an infinite loop is better in this case.