blob: fc3ef84e29953f1c9a15d023ab1232c71b20ea21 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
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 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 (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
|