-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfact.ml
53 lines (44 loc) · 1.14 KB
/
fact.ml
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(* Facts and sets of facts *)
(* Copyright (C) 2019 The MITRE Corporation
This program is free software: you can redistribute it and/or
modify it under the terms of the BSD License as published by the
University of California. *)
open Sym
type fact =
(* Predicate symbol applied to constants *)
| Q of sym * sym list
(* Function symbol applied to constants gives constant *)
| G of sym * sym list * sym
(* Comparisons *)
(* A total ordering for a list of symbols *)
let rec compr_list xs ys =
match xs, ys with
| [], [] -> 0
| [], _ :: _ -> -1
| _ :: _, [] -> 1
| x :: xs, y :: ys ->
match cmp x y with
| 0 -> compr_list xs ys
| c -> c
(* A total ordering for facts *)
let compr x y =
match x, y with
| Q (s, xs), Q (t, ys) ->
(match cmp s t with
| 0 -> compr_list xs ys
| c -> c)
| Q _, G _ -> -1
| G _, Q _ -> 1
| G (s, xs, a), G (t, ys, b) ->
match cmp s t with
| 0 ->
(match compr_list xs ys with
| 0 -> cmp a b
| c -> c)
| c -> c
module OrderedFact =
struct
type t = fact
let compare = compr
end
module FactSet = Set.Make(OrderedFact)