I am trying to define a function that evaluates to different functions depending on one of its
arguments. Some of the resulting functions refer to an implicit argument of the higher-order
function and some do not. My goal is to be able to evaluate the function without having to
provide the implicit argument even if it does not occur in the result.

When I Set Debug Cbv. before evaluating the code snippets it shows that in case ofEval term.bar is unfolded without problems. For Definition ident := Eval term.
Coq fails to do so as the implicit parameter n of bar cannot be inferred.

How can I make Definition ident := Eval term. work without having to give
the implicit argument?

Is there a better way to get implicit arguments in non-top-level functions?

It might be easier to define bar_type to take an option nat, and return nat -> nat on None and foo n -> nat on Some n. Implicit arguments, even unused ones, must be filled in, and I don’t think there’s a robust way to avoid doing that in general.