short answer: no, you can't redefine a field in an inherited object, or in 
variant branches, even if it's the same type

I hate not being able to give someone the answer they were looking for, so now, 
my eagerness to please souring to resentment, I will tell you you are wrong for 
asking the question in the first place, and assure you that you don't want to 
do it that way.

ahem.

never mind duplicating storage, you're duplicating the inheritance tree in the 
`kind` field. will you use `if x is BinaryNode` or `if x.kind in 
{Plus,Minus,Multiply,Divide}`? What if they disagree?

I suggest making ASTNode the variant 
    
    
    const BinaryKinds = {Plus,Minus,Multiply,Divide}
    type ASTNode = ref object
      startPos,endPos: Location
      case kind:NodeKind
      of FloatNumber: floatValue: float64
      of StringToken: stringValue: string
      of IntToken: intValue: int64
      of BinaryKinds: lhs,rhs:ASTNode
    
    
    Run

Reply via email to