diff options
Diffstat (limited to 'lib/evaluators/FOL.ml')
| -rw-r--r-- | lib/evaluators/FOL.ml | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/lib/evaluators/FOL.ml b/lib/evaluators/FOL.ml index e28222b..a7685bd 100644 --- a/lib/evaluators/FOL.ml +++ b/lib/evaluators/FOL.ml @@ -187,32 +187,23 @@ let rec modes = index ) let project description relation = - let open Utilities.Result in - let* cursor = Protocols.Enumerable.cursor relation in - let produce ~yield = - let* scan = Protocols.Cursor.require cursor in - let rec distinct seen = - let* next = Protocols.Cursor.next scan in - match next with - | None -> Ok () - | Some tuple -> - let tuple = - { tuple with - attributes= - BatMap.String.filter - (fun name _ -> BatMap.String.mem name description) - tuple.Concepts.Tuple.attributes } - in - let key = Concepts.Tuple.hash tuple |> Concepts.Hash.to_raw_string in - if BatSet.String.mem key seen then distinct seen - else begin - yield tuple; - distinct (BatSet.String.add key seen) - end - in - distinct BatSet.String.empty - in - Ok (Kernel.Generator.cursor_of ~finally:(fun () -> Protocols.Handle.release cursor) produce) + let seen = ref BatSet.String.empty in + Protocols.Enumerable.cursor relation + |> Result.map + (Kernel.Generator.filter_map (fun tuple -> + let tuple = + { tuple with + attributes= + BatMap.String.filter + (fun name _ -> BatMap.String.mem name description) + tuple.Concepts.Tuple.attributes } + in + let key = Concepts.Tuple.hash tuple |> Concepts.Hash.to_raw_string in + if BatSet.String.mem key !seen then None + else begin + seen := BatSet.String.add key !seen; + Some tuple + end ) ) let agrees binding {Concepts.Tuple.attributes; _} = BatMap.String.for_all |
