Version franaise
Home About Download Resources Contact us

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
How to compute variance of a type
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-01-06 (10:19)
From: Tom_Primožič <tom.primozic@g...>
Subject: How to compute variance of a type
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?