I am working on Scala 3 training materials and finding it a bit tricky to teach a simple LinkedList enum without having to introduce variance first.
enum LinkedList[A]: case Empty case NonEmpty(a: A, tail: LinkedList[A])
That won’t compile unless I declare
A as covariant or explicitly extending
LinkedList[Nothing] on the Empty case.
I wonder what Scala instructors do? Shall I go with the
extends hack or just introduce covariance at this early stage of the course?