simple-join-forest.ss
(module simple-join-forest mzscheme
  (require (lib "contract.ss")
           (lib "etc.ss")
           (planet "contract-utils.ss" ("cobbe" "contract-utils.plt" 3 0)))
  
  
  ;; join-forest: (listof X) (X X -> X) -> X
  ;;
  ;; Joins a forest, doing the simple recursive thing without
  ;; taking the contents of the nodes into account.
  (define (join-forest a-forest join-f)
    (local ((define a-forest-vec (list->vector a-forest)))
      (let loop ([i 0]
                 [j (sub1 (vector-length a-forest-vec))])
        (cond [(= i j)
               (vector-ref a-forest-vec i)]
              [else
               (let ([m (quotient (+ i j) 2)])
                 (join-f (loop i m)
                         (loop (add1 m) j)))]))))
  
  
  (provide/contract [join-forest ((nelistof/c any/c)
                                  (any/c any/c . -> . any)
                                  . -> . any)]))