From 5310ec01d756ca96babe946d44f9f3b093bc4dda Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Wed, 9 Sep 2026 21:11:56 -0300 Subject: enumerable protocol --- lib/protocols/Enumerable.ml | 21 +++++++++++++++++++++ lib/protocols/Enumerable.mli | 13 +++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 lib/protocols/Enumerable.ml create mode 100644 lib/protocols/Enumerable.mli (limited to 'lib/protocols') diff --git a/lib/protocols/Enumerable.ml b/lib/protocols/Enumerable.ml new file mode 100644 index 0000000..e78f265 --- /dev/null +++ b/lib/protocols/Enumerable.ml @@ -0,0 +1,21 @@ +module Error = struct + open Concepts.Condition + + let not_enumerable () = + condition "not-enumerable" + "A relation was used where the expression must iterate its members, but it does not support \ + enumeration. A procedural relation may decide membership without being able to produce it." + empty +end + +class type implementation = object + method enumerate : Context.t -> (Handle.t, Concepts.Condition.condition) result +end + +type Handle.protocol += Enumerable of implementation +type t = implementation + +let make impl = Enumerable (impl :> implementation) +let from handle = Handle.into handle (function Enumerable impl -> Some impl | _ -> None) +let require handle = from handle |> Option.to_result ~none:(Error.not_enumerable ()) +let enumerate i context = Handle.invoke i (fun o -> o#enumerate context) diff --git a/lib/protocols/Enumerable.mli b/lib/protocols/Enumerable.mli new file mode 100644 index 0000000..4a903f6 --- /dev/null +++ b/lib/protocols/Enumerable.mli @@ -0,0 +1,13 @@ +type t + +class type implementation = object + method enumerate : Context.t -> (Handle.t, Concepts.Condition.condition) result +end + +val make : #implementation -> Handle.protocol +val from : Handle.t -> t Handle.interface option + +val require : Handle.t -> (t Handle.interface, Concepts.Condition.condition) result + +val enumerate : + t Handle.interface -> Context.t -> (Handle.t, Concepts.Condition.condition) result -- cgit v1.2.3