generic_tree.mli 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. open Base
  2. (*** definition ***)
  3. type (+'a, +'l) tree =
  4. | Arm of 'a * ('a, 'l) tree list
  5. | Leaf of 'l
  6. type ('a, 'l) t = ('a, 'l) tree
  7. module type SHOW_EQ = sig
  8. type t
  9. val to_string : t -> string
  10. val equal : t -> t -> bool
  11. end
  12. module Make_show_eq(A: SHOW_EQ)(L: SHOW_EQ)
  13. : SHOW_EQ with type t := (A.t, L.t) tree
  14. (*** paths & zipper ***)
  15. type path = int list
  16. module Zipper : sig
  17. type (+'a, +'l) t
  18. val of_tree : ('a, 'l) tree -> ('a, 'l) t
  19. val to_tree : ('a, 'l) t -> ('a, 'l) tree
  20. module Error : sig
  21. type t = Bad_index | Not_arm | No_parent
  22. val to_string : t -> string
  23. end
  24. (* movement *)
  25. val up : ('a, 'l) t -> (('a, 'l) t, Error.t) Result.t
  26. val down : int -> ('a, 'l) t -> (('a, 'l) t, Error.t) Result.t
  27. val side : int -> ('a, 'l) t -> (('a, 'l) t, Error.t) Result.t
  28. val nav : ?prev:path -> targ:path -> ('a, 'l) t -> (('a, 'l) t, Error.t) Result.t
  29. (* accessor/modifier *)
  30. val get : ('a, 'l) t -> ('a, 'l) tree
  31. val modify : f:(('a, 'l) tree -> ('a, 'l) tree) -> ('a, 'l) t -> ('a, 'l) t
  32. val set : ('a, 'l) tree -> ('a, 'l) t -> ('a, 'l) t
  33. (* "_exn" variants *)
  34. val up_exn : ('a, 'l) t -> ('a, 'l) t
  35. val down_exn : int -> ('a, 'l) t -> ('a, 'l) t
  36. val side_exn : int -> ('a, 'l) t -> ('a, 'l) t
  37. val nav_exn : ?prev:path -> targ:path -> ('a, 'l) t -> ('a, 'l) t
  38. end