The main problem of type inference in the presence of higher-rank types is inferring polymorphic types for lambda-bound variables. In your first example, the only correct way to type foo
is to assign a polymorphic type to f
. In your second example, no such thing is needed. Instead, baz
is just a (trivial) partial application of bar
. Merely applying a higher-rank polymorphic function, without any lambda abstractions, should always be possible without additional type annotations.
See also the appropriate section in the GHC User's Guide as well as various research papers.