All the practical advice has been given, so here comes a general rant against
how generic types are named and defined:
The OP's problem started here:
type
Row* = ref object
columns: seq[string]
elements: seq[Element] # <---- Problem
Run
So many perfectly smart people who start using generics fall into this pit:
Element is not a "concrete type". And it's no wonder that they fall, because
the definition of `Element` looks like this:
type
Element = ref ElementObj
ElementObj*[T] = object
parent: string
data: T
Run
It uses the `type` keyword, so `ElementObj` and, by extension, `Element` must
be some kind of type, right? No, it isn't. It's the class of types which can be
created by calling the type constructor `ElementObj[]` with all possible values
of the type parameter `T`. `Element` is a type class, not a "generic type".
Nim should drop this confusing nomenclature inherited from `C`, call things
what they are and introduce a `typeclass` keyword for "generic types", concepts
and everything else which is not a "concrete type".