From e9b6d8a3f0582504587aaff31acc432601dd8979 Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Sun, 20 Sep 2026 02:07:22 -0300 Subject: mode concept for affordances --- lib/concepts/Mode.ml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/concepts/Mode.ml (limited to 'lib/concepts/Mode.ml') 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 -- cgit v1.2.3