aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Utilities.ml
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-09-25 21:51:33 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-09-25 21:51:33 -0300
commit584fbca6d920e9a9f91d451667f9380714ac2175 (patch)
treea163b916a6f8cb550c8b38ceb01ab01558687a40 /lib/Utilities.ml
parentc7b754e96714eeeb9d315ee3de402d73a27d47db (diff)
downloadRNT-584fbca6d920e9a9f91d451667f9380714ac2175.tar.gz
RNT-584fbca6d920e9a9f91d451667f9380714ac2175.zip
dune fmt
Diffstat (limited to 'lib/Utilities.ml')
-rw-r--r--lib/Utilities.ml42
1 files changed, 13 insertions, 29 deletions
diff --git a/lib/Utilities.ml b/lib/Utilities.ml
index fb5a7b3..c16be2e 100644
--- a/lib/Utilities.ml
+++ b/lib/Utilities.ml
@@ -7,9 +7,7 @@ end
module Option = struct
let ( let* ) = Option.bind
let fmap f m = Option.bind m f
- let sequence = function
- | None -> Ok None
- | Some x -> Result.map Option.some x
+ let sequence = function None -> Ok None | Some x -> Result.map Option.some x
end
module Result = struct
@@ -32,9 +30,8 @@ module Generic (S : SEQUENCE) = struct
(fun m acc ->
let* acc = acc in
let* m = m in
- Ok (S.cons m acc))
- ms
- (Ok S.empty)
+ Ok (S.cons m acc) )
+ ms (Ok S.empty)
end
module List = struct
@@ -42,15 +39,13 @@ module List = struct
type 'a t = 'a list
let empty = []
- let cons x xs = x::xs
+ let cons x xs = x :: xs
let fold = List.fold_right
end
include Generic (ListSequence)
- let hd_opt = function
- | x::_ -> Some x
- | [] -> None
+ let hd_opt = function x :: _ -> Some x | [] -> None
end
module FingerTree = struct
@@ -59,10 +54,7 @@ module FingerTree = struct
let empty = BatFingerTree.empty
let cons x xs = BatFingerTree.cons xs x
- let fold f xs acc = BatFingerTree.fold_right
- (Fun.flip f)
- acc
- xs
+ let fold f xs acc = BatFingerTree.fold_right (Fun.flip f) acc xs
end
include Generic (FingerTreeSequence)
@@ -71,38 +63,30 @@ module FingerTree = struct
let rec frob xs ys acc =
match BatFingerTree.front xs with
| None -> acc
- | Some (xs', x) ->
- match BatFingerTree.front ys with
- | None -> acc
- | Some (ys', y) ->
- f x y
- |> BatFingerTree.snoc acc
- |> frob xs' ys'
+ | Some (xs', x) -> (
+ match BatFingerTree.front ys with
+ | None -> acc
+ | Some (ys', y) -> f x y |> BatFingerTree.snoc acc |> frob xs' ys' )
in
frob xs ys BatFingerTree.empty
let zip xs ys = map2 (fun x y -> x, y) xs ys
let join ss sep =
- BatFingerTree.print ~first:"" ~last:"" ~sep:sep BatIO.nwrite
- |> Fun.flip BatIO.to_string ss
+ BatFingerTree.print ~first:"" ~last:"" ~sep BatIO.nwrite |> Fun.flip BatIO.to_string ss
end
module Atomic = struct
let rec swap atom f =
let v = Atomic.get atom in
let v' = f v in
- if Atomic.compare_and_set atom v v'
- then atom
- else swap atom f
+ if Atomic.compare_and_set atom v v' then atom else swap atom f
let rec mswap atom f =
let open Result in
let v = Atomic.get atom in
let* v' = f v in
- if Atomic.compare_and_set atom v v'
- then Ok atom
- else mswap atom f
+ if Atomic.compare_and_set atom v v' then Ok atom else mswap atom f
end
module Fun = struct