ocaml-standard-library/lib/tree.ml

10 lines
301 B
OCaml
Raw Normal View History

open General
2021-12-16 10:01:08 +00:00
2021-12-16 10:01:08 +00:00
let combine (tr1 : 'a tree) (tr2 : 'a tree) (topBranch : 'a) : 'a tree =
2021-12-16 20:23:03 +00:00
Branch (topBranch, tr1 :: tr2 :: [])
let rec map (f : 'a -> 'b) (tr : 'a tree) : 'b tree =
match tr with
| Branch (value, branches) -> Branch (f value, branches |> List.map (map f))
| Leaf -> Leaf