aboutsummaryrefslogtreecommitdiffstats
path: root/lib/protocols
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-09-09 21:11:56 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-09-11 01:07:39 -0300
commit5310ec01d756ca96babe946d44f9f3b093bc4dda (patch)
treee1def76aabadc1f3efcf1a6bca70298dec813cfd /lib/protocols
parentb79224410f469a1cd4ff3be4f8e62d71398109fc (diff)
downloadRNT-5310ec01d756ca96babe946d44f9f3b093bc4dda.tar.gz
RNT-5310ec01d756ca96babe946d44f9f3b093bc4dda.zip
enumerable protocol
Diffstat (limited to 'lib/protocols')
-rw-r--r--lib/protocols/Enumerable.ml21
-rw-r--r--lib/protocols/Enumerable.mli13
2 files changed, 34 insertions, 0 deletions
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