From ac2599b817cc2ad6118de501896b71b8ac70b4e9 Mon Sep 17 00:00:00 2001 From: Paul-Elliot Date: Fri, 18 Oct 2024 15:33:54 +0200 Subject: [PATCH] Compatibility --- src/utils/odoc_list.ml | 29 +++++++++++++++++++++++++++++ src/utils/odoc_utils.ml | 32 +------------------------------- src/utils/tree.ml | 2 ++ 3 files changed, 32 insertions(+), 31 deletions(-) create mode 100644 src/utils/odoc_list.ml diff --git a/src/utils/odoc_list.ml b/src/utils/odoc_list.ml new file mode 100644 index 0000000000..53ddf484c7 --- /dev/null +++ b/src/utils/odoc_list.ml @@ -0,0 +1,29 @@ +include List + +let rec concat_map ?sep ~f = function + | [] -> [] + | [ x ] -> f x + | x :: xs -> ( + let hd = f x in + let tl = concat_map ?sep ~f xs in + match sep with None -> hd @ tl | Some sep -> hd @ (sep :: tl)) + +let rec filter_map acc f = function + | hd :: tl -> + let acc = match f hd with Some x -> x :: acc | None -> acc in + filter_map acc f tl + | [] -> List.rev acc + +let filter_map f x = filter_map [] f x + +(** @raise [Failure] if the list is empty. *) +let rec last = function + | [] -> failwith "Odoc_utils.List.last" + | [ x ] -> x + | _ :: tl -> last tl + +(* From ocaml/ocaml *) +let rec find_map f = function + | [] -> None + | x :: l -> ( + match f x with Some _ as result -> result | None -> find_map f l) diff --git a/src/utils/odoc_utils.ml b/src/utils/odoc_utils.ml index 4623fc9035..9d7b8d2250 100644 --- a/src/utils/odoc_utils.ml +++ b/src/utils/odoc_utils.ml @@ -45,37 +45,7 @@ module EitherMonad = struct let of_result = function Result.Ok x -> Right x | Error y -> Left y end -module List = struct - include List - - let rec concat_map ?sep ~f = function - | [] -> [] - | [ x ] -> f x - | x :: xs -> ( - let hd = f x in - let tl = concat_map ?sep ~f xs in - match sep with None -> hd @ tl | Some sep -> hd @ (sep :: tl)) - - let rec filter_map acc f = function - | hd :: tl -> - let acc = match f hd with Some x -> x :: acc | None -> acc in - filter_map acc f tl - | [] -> List.rev acc - - let filter_map f x = filter_map [] f x - - (** @raise [Failure] if the list is empty. *) - let rec last = function - | [] -> failwith "Odoc_utils.List.last" - | [ x ] -> x - | _ :: tl -> last tl - - (* From ocaml/ocaml *) - let rec find_map f = function - | [] -> None - | x :: l -> ( - match f x with Some _ as result -> result | None -> find_map f l) -end +module List = Odoc_list module Option = struct let map f = function None -> None | Some x -> Some (f x) diff --git a/src/utils/tree.ml b/src/utils/tree.ml index 16785a8f32..6941ec865f 100644 --- a/src/utils/tree.ml +++ b/src/utils/tree.ml @@ -1,3 +1,5 @@ +module List = Odoc_list + type 'a t = { node : 'a; children : 'a forest } and 'a forest = 'a t list