aboutsummaryrefslogtreecommitdiffstats
path: root/lib/concepts/Mode.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/concepts/Mode.ml')
-rw-r--r--lib/concepts/Mode.ml30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/concepts/Mode.ml b/lib/concepts/Mode.ml
new file mode 100644
index 0000000..b7aa814
--- /dev/null
+++ b/lib/concepts/Mode.ml
@@ -0,0 +1,30 @@
+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 attributes_of_map map = BatMap.String.keys map |> BatSet.String.of_enum
+let decides_when bound = {bound= attributes_of_list bound; affords= Decides}
+let enumerable cardinality = {bound= BatSet.String.empty; affords= Generates cardinality}
+let of_list modes = modes
+
+let generation declaration bound =
+ List.fold_left
+ (fun tightest {bound= declared; affords} ->
+ match affords with
+ | Generates cardinality when BatSet.String.subset declared bound ->
+ Some (Option.fold ~none:cardinality ~some:(Cardinality.meet cardinality) tightest)
+ | Generates _ | Decides -> tightest )
+ None declaration
+
+let exhaustible declaration bound =
+ Option.fold ~none:false ~some:Cardinality.exhaustible (generation declaration bound)
+
+let decision declaration bound =
+ exhaustible declaration bound
+ || List.exists
+ (fun {bound= declared; affords} ->
+ match affords with Decides -> BatSet.String.equal declared bound | Generates _ -> false )
+ declaration