The most pressing unsolved problem. Assume we have:
    
    
    type
      IfTree = object
        condition, thenPart, elsePart: Tree
      
      ProcTree = object
         fn: Tree
         args: seq[Tree]
      
      UnaryOp = object
        arg: Tree
      
      Tree = ref case
          of StrValue: string
          of IntValue: int
          of IfStmt: IfTree
          of ProcCall: ProcTree
          of Minus, BitwiseNot: UnaryOp
    
    
    
    Run

And now we pattern match:
    
    
    let x = ProcCall(fn: StrValue"abc", args: @[]) # some test data
    case x
    of StrValue(s):
       # s is of type: string
    of IfStmt(cond, thenPart, elsePart):
       # obvious unpacking: cond, thenPart, elsePart of type: Tree
    of ProcCall: ..
    of Minus(x):
       # is x of type UnaryOp or of type Tree?
    
    
    
    Run

Reply via email to