FWIW, the read/write distinction really helps me to remember the terms:

For reading, you want to be sure the array you’ve got contains values at least 
as specific as you were expecting. So, if you’re expecting Integer, it’s fine 
if you get Int. In that case, you might hope that Vector{Int} <: 
Vector{Integer}. In other words, reading => covariance, which involves 
following type arrows in their true direction.

For writing, you want to be sure the array you’ve got contains values at least 
as general as you were expecting. So, if you’re expecting Int, it’s fine if you 
get Integer. In that case, you might hope that Vector{Integer} <: Vector{Int}. 
In other words, writing => contravariance, which involves going backwards along 
type arrows.

If you want to be able to read and write, you need to avoid allowing covariance 
and contravariance. When you entirely refuse to look at type arrows, you get 
invariance.

 — John

On Aug 15, 2014, at 7:58 PM, Brendan O'Connor <[email protected]> wrote:

> On Fri, Aug 15, 2014 at 9:53 PM, John Myles White <[email protected]> 
> wrote:
> Hi Brendan,
> 
> It looks like you’re hitting Julia’s invariance for the first time: 
> http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)
> 
> Oh nice.  I could never keep the covariance/contravariance directions 
> straight, anyway...

Reply via email to