Здравствуйте, Mangar, Вы писали:
<skipped/>
если seq заменить за list, можно сделать что-то такое:
type 'T Tree =
| Leaf of 'T
| Node of 'T * list<'T Tree>
let foldTree fLeaf fNode t =
let rec processNode node k =
match node with
| Leaf(v) -> k (fLeaf v)
| Node (v, nodes) -> processList nodes (fun rs -> k (fNode v rs)) []
and processList nodes k acc =
match nodes with
| [] -> k (List.rev acc)
| x::xs -> processNode x (fun r -> processList xs k (r::acc))
processNode t id
let height t =
foldTree
(fun x -> 1)
(fun x xs -> 1 + List.max xs)
t