diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-09-25 21:51:33 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-09-25 21:51:33 -0300 |
| commit | 584fbca6d920e9a9f91d451667f9380714ac2175 (patch) | |
| tree | a163b916a6f8cb550c8b38ceb01ab01558687a40 /lib/kernel/Prototype.ml | |
| parent | c7b754e96714eeeb9d315ee3de402d73a27d47db (diff) | |
| download | RNT-584fbca6d920e9a9f91d451667f9380714ac2175.tar.gz RNT-584fbca6d920e9a9f91d451667f9380714ac2175.zip | |
dune fmt
Diffstat (limited to 'lib/kernel/Prototype.ml')
| -rw-r--r-- | lib/kernel/Prototype.ml | 130 |
1 files changed, 67 insertions, 63 deletions
diff --git a/lib/kernel/Prototype.ml b/lib/kernel/Prototype.ml index b159e00..4c96bc3 100644 --- a/lib/kernel/Prototype.ml +++ b/lib/kernel/Prototype.ml @@ -1,24 +1,24 @@ -let mixture ps = Protocols.Handle.make @@ - object - inherit Lifecycle.null - inherit Identity.of_id (* Should we allow the user to override this? *) +let mixture ps = + Protocols.Handle.make + @@ object + inherit Lifecycle.null + inherit Identity.of_id (* Should we allow the user to override this? *) + method protocols = ps + method to_string = "mixture" + end - method protocols = ps - - method to_string = "mixture" - end - -let rec mixture_of value f = - mixture (f (fun value' -> mixture_of value' f) value) +let rec mixture_of value f = mixture (f (fun value' -> mixture_of value' f) value) module Error = struct open Concepts.Condition - let invalid_property key = condition "invalid-property" "The specified key does not correspond to any property of the object" - ("key" |=| Concepts.Value.String key) + let invalid_property key = + condition "invalid-property" + "The specified key does not correspond to any property of the object" + ("key" |=| Concepts.Value.String key) - let deletion_not_supported () = condition "deletion-not-supported" "Attempting to delete an object property" - empty + let deletion_not_supported () = + condition "deletion-not-supported" "Attempting to delete an object property" empty end module Addressable = struct @@ -26,75 +26,79 @@ module Addressable = struct module Tree = Merkle.Make (S) (K) let make ~node = - Protocols.Addressable.make @@ - object - method address = Tree.hash_of node - end + Protocols.Addressable.make + @@ object + method address = Tree.hash_of node + end end end module Associative = struct let of_properties props = - Protocols.Associative.make @@ - object - val props = BatList.to_seq props |> BatMap.of_seq + Protocols.Associative.make + @@ object + val props = BatList.to_seq props |> BatMap.of_seq - method update key value = - match BatMap.find_opt key props with - | None -> Error (Error.invalid_property key) - | Some f -> f value - end + method update key value = + match BatMap.find_opt key props with + | None -> Error (Error.invalid_property key) + | Some f -> f value + end - let update_only f = function - | None -> Error (Error.deletion_not_supported ()) - | Some x -> f x + let update_only f = function None -> Error (Error.deletion_not_supported ()) | Some x -> f x module OfTree (S : Abstract.Storage.STORAGE) (K : Merkle.KEY with type t = string) = struct module Tree = Merkle.Make (S) (K) module SI = Storage.Make (S) let make ~storage ~constructor ~node = - Protocols.Associative.make @@ - object - method update key value = - (* TODO: read-only transactions *) - SI.with_transaction storage (fun tx -> - let open Utilities.Result in - let open Protocols in - let* node' = match value with - | None -> Tree.remove tx key node - | Some h -> - let* addressable = Handle.require Addressable.from h in - let addr = Addressable.address addressable in - Tree.insert tx key addr node - in - constructor node') - end + Protocols.Associative.make + @@ object + method update key value = + (* TODO: read-only transactions *) + SI.with_transaction storage (fun tx -> + let open Utilities.Result in + let open Protocols in + let* node' = + match value with + | None -> Tree.remove tx key node + | Some h -> + let* addressable = Handle.require Addressable.from h in + let addr = Addressable.address addressable in + Tree.insert tx key addr node + in + constructor node' ) + end end end module Directory = struct let of_properties props = - Protocols.Directory.make @@ - object - val props = BatList.to_seq props |> BatMap.of_seq - - method list = Ok (BatMap.keys props |> BatFingerTree.of_enum) - method find k = Ok (BatMap.find_opt k props) - end - - module OfTree (S : Abstract.Storage.STORAGE) (K : Merkle.KEY with type t = string) (V : Merkle.VALUE) = struct + Protocols.Directory.make + @@ object + val props = BatList.to_seq props |> BatMap.of_seq + method list = Ok (BatMap.keys props |> BatFingerTree.of_enum) + method find k = Ok (BatMap.find_opt k props) + end + + module OfTree + (S : Abstract.Storage.STORAGE) + (K : Merkle.KEY with type t = string) + (V : Merkle.VALUE) = + struct module Tree = Merkle.Interface (S) (K) (V) module SI = Storage.Make (S) let make ~storage ~constructor ~node = - Protocols.Directory.make @@ - object - method list = SI.with_transaction storage (Fun.flip Tree.keys node) - method find k = SI.with_transaction storage (fun tx -> Tree.lookup tx k node) - |> Utilities.Result.fmap (function - | None -> Ok None - | Some x -> constructor x |> Result.map (Option.some)) - end + Protocols.Directory.make + @@ object + method list = SI.with_transaction storage (Fun.flip Tree.keys node) + + method find k = + SI.with_transaction storage (fun tx -> Tree.lookup tx k node) + |> Utilities.Result.fmap (function + | None -> Ok None + | Some x -> constructor x |> Result.map Option.some ) + end end end |
