generic_tree.mli 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 set : ('a, 'l) tree -> ('a, 'l) t -> ('a, 'l) t
  32. (* "_exn" variants *)
  33. val up_exn : ('a, 'l) t -> ('a, 'l) t
  34. val down_exn : int -> ('a, 'l) t -> ('a, 'l) t
  35. val side_exn : int -> ('a, 'l) t -> ('a, 'l) t
  36. val nav_exn : ?prev:path -> targ:path -> ('a, 'l) t -> ('a, 'l) t
  37. end