From bd6acf89e0ecb53bc436c2586175387f4b10fe91 Mon Sep 17 00:00:00 2001 From: Emin Arslan Date: Wed, 11 Feb 2026 23:40:17 +0300 Subject: [PATCH] util: separated the monadic traverse into a utility module --- lib/compiler/syntactic_ast.ml | 8 +------- lib/compiler/util.ml | 9 +++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 lib/compiler/util.ml diff --git a/lib/compiler/syntactic_ast.ml b/lib/compiler/syntactic_ast.ml index ea4460b..23be618 100644 --- a/lib/compiler/syntactic_ast.ml +++ b/lib/compiler/syntactic_ast.ml @@ -34,13 +34,7 @@ type top_level = (* we use result here to make things nicer *) let ( let* ) = Result.bind -let traverse f l = - let rec aux acc = function - | x :: xs -> - let* result = f x in - aux (result :: acc) xs - | [] -> Ok (List.rev acc) in - aux [] l +let traverse = Util.traverse let map = List.map diff --git a/lib/compiler/util.ml b/lib/compiler/util.ml new file mode 100644 index 0000000..71512db --- /dev/null +++ b/lib/compiler/util.ml @@ -0,0 +1,9 @@ +let ( let* ) = Result.bind + +let traverse f l = + let rec aux acc = function + | x :: xs -> + let* result = f x in + aux (result :: acc) xs + | [] -> Ok (List.rev acc) in + aux [] l