[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | rossberg@p... |
| Subject: | Re: [Caml-list] How to compute variance of a type |
Tom Primožiè wrote:
>
> 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?
Off-hand I don't have any easy resources I could point to, but the basic
rule is very simple: whenever you descent into a type argument where the
respective type constructor has negative polarity (like the left argument
of "->"), you just negate the variances. Thus, in your example, long_funct
is covariant in 'a and 'c, and contravariant in 'b. It is straightforward
to formulate that as a recursive algorithm.
- Andreas