I am writing a type inference engine for a simple ML-like language, and I am wondering how to infer the variance of type parameters. I know a little about variance already, so I could figure it out for some basic cases, like in type
type ('a, 'b) funct = 'a -> 'b
the type variable 'a is contravariant, and 'b is covariant, and in case one variable would be co- and contravariant at the same time, it is invariant
type ('a, 'b) both = Left of 'a -> 'b | Right of 'b -> 'a.
But I have no idea on how to compute variance of complex types, like
type ('a, 'b, 'c) long_funct = ('a -> 'b) -> 'c
since the whole ('a -> 'b) is in contravariant position, so 'a is twice contravariant, and b is first contra-, and the covariant.
Any resources?