Hello. I know that when a type is of `ref`, you need to construct it with 
`new(return)` within a function. However how does one construct the type that's 
wrapped inside an Option?
    
    
    type
        Tree*[T] = ref object of RootObj
            item: T
            parent, left, right: Tree[T]
    
    # If I didn't have to construct, I would write the function like:
    proc searchTree*[T](leaf: Tree[T]; search_for: T): Option[Tree[T]] =
        if leaf.isNil():
            return result # which is none(Tree[T])
        elif leaf.item == search_for:
            result = some(leaf)
            return result
        elif search_for < leaf.item:
            result = searchTree(leaf, searchFor)
            return result
        else:
            result = searchTree(leaf.right, searchFor)
    
    
    Run

Reply via email to