blob: d1a6fcc78053dac9fb9a0b77e5ab6a3e3be91ff1 (
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
|
type value = Obj.t
type tuple = (string * value) list
type implementation =
{ membership_criteria: (tuple -> (bool, string) result) option;
produce: (tuple -> (tuple list, string) result) option }
(* TODO: Rethink this instead in terms of a value.
We need to store the references as a normal relation
on the multigroup relation catalog. *)
let registry : (string, implementation) Hashtbl.t = Hashtbl.create 32
let mutex = Mutex.create ()
let register symbol impl = Mutex.protect mutex (fun () -> Hashtbl.replace registry symbol impl)
let find symbol = Mutex.protect mutex (fun () -> Hashtbl.find_opt registry symbol)
let symbols () = Mutex.protect mutex (fun () -> Hashtbl.to_seq_keys registry |> List.of_seq)
let implementation_of_rows ?membership_criteria (rows : tuple list) : implementation =
{membership_criteria; produce= Some (fun _bindings -> Ok rows)}
let implementation_of_producer ?membership_criteria (produce : tuple -> (tuple list, string) result)
: implementation =
{membership_criteria; produce= Some produce}
let implementation_of_unit_producer ?membership_criteria
(produce : unit -> (tuple list, string) result) : implementation =
{membership_criteria; produce= Some (fun _bindings -> produce ())}
|