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

  let not_a_relation () =
    condition "not-a-relation" "A handle was expected to carry the relation protocol and did not"
      empty
end

class type implementation = object
  method contains : Concepts.Tuple.t -> (bool, Concepts.Condition.condition) result
end

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

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