Insert Node into a Tree - Racket
问题 I am trying to add a new node to the tree. The following are my definitions and function type: (define-struct (Some T) ([value : T])) (define-type (Option T) (U 'None (Some T))) (define-type BST (U 'E Nd)) (define-struct Nd ([root : Integer] [lsub : BST] [rsub : BST])) (: insert : Integer BST -> BST) ;; insert an item into a tree ;; note: do not insert duplicate items (define (insert n x) (match x ('E 'E) ((Nd ro ls rs) (cond ((= (size x) 1) (Nd ro (Nd n 'E 'E) 'E)) (else (Nd ro ls rs))))))