> `var a:seq[A] = @[B(val:1), B(val:2)]` > can not work as Nim is a statically
> typed language, seq[A] and seq[B] are different types, so assignment is not
> allowed.
There's nothing about static typing that forbids this; the collection class
just needs the appropriate generic assignment operator. I thought C++'s
`vector` allowed it, but I just tried it and it doesn't. But Swift's `Array`
does, so this compiles:
// This is Swift 5.2
class A { }
class B : A { }
var a: [A] = []
var b: [B] = []
a = b
Run
In Nim I think you could write a generic proc to assign a `seq[B]` to a
`seq[A]`, using the restriction `when B is A`.