I think you need to define at which level your list is heterogeneous.
If you have a seq[T] with T being a runtime type, you have to use type erasure,
either through object variants or through inheritance.
Here is your example fixed. Now you can just transform the Packet type into an
object variant or a ref object of RootObj so that it can hold heterogenous
runtime data.
type
Packet = ref object
data: string
# Not to sure what you tried to do with the concept
HgCell[T, S] = object
data: T
handler: proc(dat: T, buffer: S): void
HgPack[T, S] = object
buffer: S
cells: seq[HgCell[T, S]]
proc pack*(p: Packet, i: int8) =
p.data &= $i
proc initHgPack*[T, S](): auto = HgPack[T, S](cells: @[])
proc register*[S; T](msgp: var HgPack[T, S], elem: T, handler: proc(dat: T,
b: S)) =
# Failure reason:
# - S; T not S, T otherwise S, T: Restriction apply to both
# - msgp needs to be a var
# - you need msp.cells.add
# - you need to specify the generics for HgCell isntantiation
msgp.cells.add(
HgCell[T, S](data: elem, handler: handler)
)
var mp = initHgPack[int8, Packet]() # mp needs to be var
mp.register(1, proc(i: int8, buff: Packet) = buff.pack(i))
Run