[
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: | 2001-04-29 (10:22) |
From: | Jacques Garrigue <garrigue@k...> |
Subject: | Re: [Caml-list] co/contra-variance and class ? |
From: Juergen Pfitzenmaier <pfitzen@informatik.uni-tuebingen.de> > It is nice to see the introduction of explicit co/contra-variance > into ocaml. I just read the manual and didn't try some code, but > my understanding is that the variance stuff is only for type definitions > and not for classes. Why is this so ? Variance can be a mighty > tool in dealing with class hierarchies. Actually variance annotations are also allowed for type parameters in classes. I just forgot to add this to the reference manual. To be more precise: explicit variance annotations are only useful on abstract types. In all other cases covariance and contravariance of type parameters is automatically computed. So the question is rather: why can you write variance annotations on concrete types also. At the beginning, this was just a syntax problem: you cannot simultaneously allow annotations for abstract types and refuse them in other cases. Then it appeared that they could be useful to check the variance of a type parameter: since the compiler only shows the variance of type parameters for abstract types, in other cases writing it by hand will make sure that the parameters have at least the variance expected (but they can be stronger). Cheers, Jacques Garrigue ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr