From c9e8dff919c49a13bff601e78cc1e78a7cc8f506 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 8 Aug 2021 17:38:33 +0530 Subject: dump --- src/utils.ml | 53 +++++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) (limited to 'src/utils.ml') diff --git a/src/utils.ml b/src/utils.ml index 8d1094e..62ae3a5 100644 --- a/src/utils.ml +++ b/src/utils.ml @@ -1,36 +1,33 @@ -module Utils = struct - exception Empty_list - let fold fn = function - | [] -> raise Empty_list - | head :: tail -> List.fold_left fn head tail +exception Empty_list +let fold fn = function + | [] -> raise Empty_list + | head :: tail -> List.fold_left fn head tail - let list_min ls = fold Stdlib.min ls - let list_max ls = fold Stdlib.max ls +let list_min ls = fold Stdlib.min ls +let list_max ls = fold Stdlib.max ls - let rec repeat n a = - if n <= 0 - then [] - else a :: repeat (n - 1) a +let rec repeat n a = + if n <= 0 + then [] + else a :: repeat (n - 1) a - let empty ls = (ls = []) +let empty ls = (ls = []) - let rec zip l1 l2 = - match (l1, l2) with - | ([], _) -> [] - | (_, []) -> [] - | (h1 :: t1, h2 :: t2) -> (h1, h2) :: zip t1 t2 +let rec zip l1 l2 = + match (l1, l2) with + | ([], _) -> [] + | (_, []) -> [] + | (h1 :: t1, h2 :: t2) -> (h1, h2) :: zip t1 t2 - let rec transpose = function - | [] :: _ -> [] - | ls -> List.(map hd ls) :: transpose List.(map tl ls) +let rec transpose = function + | [] :: _ -> [] + | ls -> List.(map hd ls) :: transpose List.(map tl ls) - let flip f a b = f b a +let flip f a b = f b a - let rot_right ls = List.(rev ls |> transpose) - let rot_left ls = List.(transpose ls |> rev) - - let saturating_sub b a = - if a < b then 0 - else a - b -end +let rot_right ls = List.(rev ls |> transpose) +let rot_left ls = List.(transpose ls |> rev) +let saturating_sub b a = + if a < b then 0 + else a - b -- cgit v1.2.3