aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-09-20 02:07:22 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-09-20 02:07:22 -0300
commite9b6d8a3f0582504587aaff31acc432601dd8979 (patch)
treefdb501ee4b30f38be603edc79214d75d40bcc9cc /lib
parenta597aa80835411d44942d147a2143a737046d733 (diff)
downloadRNT-e9b6d8a3f0582504587aaff31acc432601dd8979.tar.gz
RNT-e9b6d8a3f0582504587aaff31acc432601dd8979.zip
mode concept for affordances
Diffstat (limited to '')
-rw-r--r--lib/concepts/Mode.ml39
-rw-r--r--lib/concepts/Mode.mli26
2 files changed, 65 insertions, 0 deletions
diff --git a/lib/concepts/Mode.ml b/lib/concepts/Mode.ml
new file mode 100644
index 0000000..4d7501c
--- /dev/null
+++ b/lib/concepts/Mode.ml
@@ -0,0 +1,39 @@
+type attribute = string
+type attributes = BatSet.String.t
+type affordance = Decides | Generates of Cardinality.t
+type mode = {bound: attributes; affords: affordance}
+type t = mode list
+
+let attributes_of_list = BatSet.String.of_list
+
+let decides_when bound = {bound= attributes_of_list bound; affords= Decides}
+
+let generates_when bound cardinality =
+ {bound= attributes_of_list bound; affords= Generates cardinality}
+
+let enumerable cardinality = {bound= BatSet.String.empty; affords= Generates cardinality}
+
+let empty = []
+let declare mode declaration = mode :: declaration
+let of_list modes = modes
+let to_list declaration = declaration
+
+let generation declaration bound =
+ List.fold_left
+ (fun tightest {bound= declared; affords} ->
+ match affords with
+ | Generates cardinality when BatSet.String.subset declared bound ->
+ Some
+ ( match tightest with
+ | None -> cardinality
+ | Some other -> Cardinality.meet cardinality other )
+ | Generates _ | Decides -> tightest )
+ None declaration
+
+let decision declaration bound =
+ List.exists
+ (fun {bound= declared; affords} ->
+ match affords with
+ | Decides -> BatSet.String.equal declared bound
+ | Generates _ -> false )
+ declaration
diff --git a/lib/concepts/Mode.mli b/lib/concepts/Mode.mli
new file mode 100644
index 0000000..57b079f
--- /dev/null
+++ b/lib/concepts/Mode.mli
@@ -0,0 +1,26 @@
+type attribute = string
+type attributes = BatSet.String.t
+
+(** what asking a relation under a given set of bound attributes
+ affords. The answer is to whether anything satisfies the binding,
+ or the bindings of the attributes left free together with the
+ class of what is produced. *)
+type affordance = Decides | Generates of Cardinality.t
+
+type mode = {bound: attributes; affords: affordance}
+type t
+
+val attributes_of_list : attribute list -> attributes
+val decides_when : attribute list -> mode
+val generates_when : attribute list -> Cardinality.t -> mode
+val enumerable : Cardinality.t -> mode
+val empty : t
+val declare : mode -> t -> t
+val of_list : mode list -> t
+val to_list : t -> mode list
+
+(** the tightest class declared for generating under [bound]. A mode
+ declared for fewer bound attributes applies to more, since the
+ attributes left free are then fewer and no more numerous. *)
+val generation : t -> attributes -> Cardinality.t option
+val decision : t -> attributes -> bool