Luis Orduz

Software engineer, occasional writer, and movie watcher.

Type variance

| by in Notes

I spent a while fixing up the genetic algorithm I wrote a while ago; up until the version that is up now, I didn't really like how it looked and the reason was the type hints. It simply didn't click to me why the classes from the implementation weren't compatible with the protocols in the definition and why I had to create the type variables (which I find really ugly, and hopefully won't be required anymore in the near future). Reading up on how to improve it led me to the concept of variance, of which I only had a vague memory from college.

Writing this note to ensure it doesn't become a vague memory again: