Overloading a newT proc? 
    
    
    type TKind = enum
      A, B
    
    type T = object
      s: string
      case kind: TKind
        of A:
          a: int
        of B:
          b: string
    
    # for TKind A
    # assuming TKind A can be derived from fact that second
    # parameter 'a: int'
    proc newT(s: string, a: int): T =
      T(s: s, kind: A, a: a)
    
    # for TKind B
    proc newT(s: string, b: string): T =
      T(s: s, kind: B, b: b)
    
    var
       ta = T(s: "hoi", kind: A, a: 123)
       tb = T(s: "bye", kind: B, b: "yippie")
    
    echo "ta = ", ta
    echo "tb = ", tb
    
    echo "-----"
    
    ta = newT("hoi again", 456)
    tb = newT("bye again", "oops")
    
    echo "ta = ", ta
    echo "tb = ", tb
    
    Run

Reply via email to