# Version without futures

lam input is
  let append = Fun a in   # Append two lists (represented as rightist trees)
    fun append (xs) is lam ys is
      case xs of
        Leaf => ys
      | Node(x,l,r) => Node(x, Leaf, append r ys)
      end
    end end end : All a. a tree -> a tree -> a tree
  in
  let collect = Fun a in
     fun collect (f) is lam t is
       case t of
         Leaf => Leaf
       | Node(x,l,r) =>
           let ls = collect f l  in
           let rs = collect f r  in
           let rest = append[a] ls rs  in
               if f(x) then
                  Node(x,Leaf, rest)
               else
                  rest
               fi
           end end end
       end #case
     end end end : All a. (a -> bool) -> a tree -> a tree  # that is, `a list'
  in
    collect[int] (fun g (x) is 3 < x end) input
  end
  end
end : int tree -> int tree   # == int list
;
