> But, to my knowledge, that really isn't possible in a compiled language.

It is possible, you can either use ['case 
objects'](https://nim-lang.org/docs/manual.html#types-object-variants): 
    
    
    # A
    type
      PlayerKind = enum pkHUMAN pkCPU
      Player = object
        case kind: PlayerKind
        of pkCPU:
          level: int
        else:
          discard
    
    let list = @[Player(kind: pkHUMAN), Player(kind: pkCPU)]
    

Or [ref objects + 
inheritance](https://nim-lang.org/docs/manual.html#types-tuples-and-object-types):
 
    
    
    # B
    type
      Player = ref object of RootObj
      PlayerHuman = ref object of Player
      PlayerCPU = ref object of Player
    
    let list = @[PlayerHuman().Player, PlayerHuman(), PlayerCPU()]
    

Reply via email to