Redundant parameter evaluates to ('a -> 'a) why not just 'a,'b or ('b -> 'c)?

I have defined the following function:

let rec g2 f h n x =
match n with
|0 -> x
| n -> g2 h f (n-1) (f x);;

Running it, I get the type

g2: ('a->'a) → ('a->'a) → int → 'a → 'a

All of these types make sense to me except for h:

I can see how h can essentially be any type whatsoever, because it isn’t used in g2, which has me wondering why specifically it is a function?

Also, why does it map from ('a → 'a) if it can be any function? Wouldn’t a more general type be mapping from one domain to another? I.g ('b → 'c) rather than from the same to the same?

Of course this question assumes, that F#'s type inference evaluates to the most general type, if this isn’t the case, am I right in assuming ('b → 'c) is more general than ('a → 'a)?

h and f have to be the same type, because in your recursive call you flip the order. The definition says g2 f h ... and the recursive call says g2 h f .... Since f has to be 'a -> 'a, h does too.

2 Likes