Well direct casting is unsafe and is to be avoided especially for generics. If 
the program flow allows it's best to just write.
    
    
    var myVideo = TVideo()
    var myVideoList = @[TMedia myVideo] # No need to cast when it's not a video 
list
    setNewDims(myVideoList)
    
    
    Run

The best way to write the generic solution is
    
    
    proc setNewDims[T: Media](arr:seq[T])=
       echo arr[0].id
    
    
    Run

Nim's generics over inheritance are invariant, this means that just cause two 
generic parameters are interchangeable the overall type instance is not. It is 
not a simple problem given you can have the following typedef:
    
    
    type MyType[T] = object
      when T is Video:
        someVal: int
      else:
       someOtherVal: float
    
    
    Run

Reply via email to