Пожалуйста, как мне сделать, чтобы эта функция возвращала значение каждой ветви и листа в виде плавающего списка? Я попробовал несколько методов с рекурсией Tail, но я не могу вернуть голову, которую я не могу пройти через ветвь и лист.
type 'a Tree = | Leaf of 'a | Branch of 'a Tree * 'a Tree
let medianInTree (lst: float Tree) :float list=
let rec medianInTree' (a : float Tree) acc =
match lst with
| Leaf(n) -> n :: acc
| Branch(Leaf(xx), Leaf(xs)) -> xx :: [xs]
| Branch(Leaf(x), Branch(Leaf(xx), Leaf(xs))) ->
let acc = medianInTree'(Leaf(x)) acc
medianInTree' (Branch(Leaf(xx), Leaf(xs))) acc
| Branch(_, _) -> []
medianInTree' lst []
Вопрос: medianInTree (Branch(Leaf(2.0), Branch(Leaf(3.0), Leaf(5.0))))
Я хочу этот результат: [2,0; 3,0; 5,0]