aboutsummaryrefslogtreecommitdiffstats
path: root/lib/protocols/Admission.ml
blob: 5a20105b059243318eda862d54c6c9320eb93421 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Error = struct
  open Concepts.Condition

  let not_admitting () =
    condition "not-admitting" "A handle was expected to carry the admission protocol and did not"
      empty
end

type violations = (string * Concepts.Tuple.t list) list

class type implementation = object
  method check : (violations, Concepts.Condition.condition) result
end

type Handle.protocol += Admission of implementation
type t = implementation

let make impl = Admission (impl :> implementation)
let from handle = Handle.into handle (function Admission impl -> Some impl | _ -> None)
let require handle = from handle |> Option.to_result ~none:(Error.not_admitting ())
let check i = Handle.invoke i (fun o -> o#check)