aboutsummaryrefslogtreecommitdiffstats
path: root/lib/concepts/Mode.ml
blob: 9c5daa966e3be9974fef1e5f110ac78ad1c1d07e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
type attributes = BatSet.String.t
type mode = {bound: attributes; yields: Cardinality.t}
type t = mode list

let mode bound yields = {bound= BatSet.String.of_list bound; yields}

let generation modes bound =
  List.fold_left
    (fun tightest {bound= declared; yields} ->
      if BatSet.String.subset declared bound then
        Some (Option.fold ~none:yields ~some:(Cardinality.meet yields) tightest)
      else tightest )
    None modes

let exhaustible modes bound =
  Option.fold ~none:false ~some:Cardinality.exhaustible (generation modes bound)

let project attributes = List.filter (fun {bound; _} -> BatSet.String.subset bound attributes)

let given attribute =
  List.map (fun {bound; yields} -> {bound= BatSet.String.remove attribute bound; yields})