Coercion of arrays of objects (and some other containers)

Martin Jambon
 Olivier Andrieu

Jacques Garrigue

Matthieu Dubuget
 Olivier Andrieu

Matthieu Dubuget
[
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:  Olivier Andrieu <andrieu@i...> 
Subject:  Re: [Camllist] Coercion of arrays of objects (and some other containers) 
Matthieu Dubuget [Wed, 13 Apr 2005]: > I'm sorry, but I feel stupid. > > The variance and covariance terms/notions appear often in this > list, and seems to be very basic notions. > > I tried to find explanation on internet but did not succeed. > > Could somebody point me some links to understand, please? I do not have a link but the idea (as I understand it) is simple : This concerns parameterized types ('a t) and how a subtyping relation on the parameter can yield a subtyping relation on the type. When the parameter is covariant : if a is a subtype of b then a t is a subtype of b t When the parameter is contravariant : if a is a subtype of b then b t is a subtype of a t For instance lists are covariant. [`A`B`C] is a supertype of [`A`B] so a [`A`B`C] list is a supertype of [`A`B] list. Function arguments are contravariant : ([`A`B] > unit) is a supertype of ([`A`B`C] > unit). When you have a function that accepts A B or C, you can also view it as a function that accepts just A or B (qui peut le plus peut le moins). Records with mutable fields (or arrays) are neither covariant nor contravariant. Well maybe my terminology isn't quite correct but I hope you get the idea.  Olivier