Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sure, you can keep telling me that and it doesn't stay. I'm completely happy writing Rust, and I am aware it needs variance to work in principle and when I do need that information I know the magic words to type into doc search.

It's like how I can hold in my head how classical DH KEX works and I can write a toy version with numbers that are too small - but for the actual KEX we use today, which is Elliptic Curve DH I'm like "Well, basically it's the same idea but the curves hurt my head so I just paste in somebody else's implementation" even in a toy.

Sorry?



One day the rote example finally made sense to me, and I go back to it every time I hear about variance.

Got a Container<Animal> and want to treat it as a Container<Cat>? Then you can only write to it: it's ok to put a Cat in a Container<Cat> that's really a Container<Animal>.

Reading from it is wrong. If you treat a Container<Animal> like a Container<Cat> and read from it, you might get a Dog instead.

The same works in reverse, treating a Container<Cat> like a Container<Animal> is ok for read, but not for write.


The usual way of phrasing this is, famously, https://en.wikipedia.org/wiki/A_white_horse_is_not_a_horse




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: