forked from caterinaurban/function
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbanal_datatypes.ml
106 lines (68 loc) · 1.91 KB
/
banal_datatypes.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
(*
Useful datatypes and functor instantiations.
Copyright (C) 2011 Antoine Miné
*)
(* unique identifiers *)
(* ****************** *)
type id = Z.t
let cur_id = ref Z.zero
let new_id () =
cur_id := Z.succ !cur_id; !cur_id
let string_of_id prefix id =
prefix^(Z.to_string id)
let compare_id (x:id) (y:id) = compare x y
let dummy_id = Z.minus_one
(* maps and sets *)
(* ************* *)
module StringSet = Set.Make(struct type t=string let compare=compare end)
module StringMap = Mapext.Make(struct type t=string let compare=compare end)
module IdSet = Set.Make(struct type t=id let compare=compare_id end)
module IdMap = Mapext.Make(struct type t=id let compare=compare_id end)
(* 3-valued logic *)
(* ************** *)
type tbool = True | False | Maybe
let tnot = function
| True -> False
| False -> True
| Maybe -> Maybe
let tor a b =
match a,b with
| True,_ | _,True -> True
| Maybe,_ | _,Maybe -> Maybe
| False,False -> False
let tand a b =
match a,b with
| False,_ | _,False -> False
| Maybe,_ | _,Maybe -> Maybe
| True,True -> True
let tbool_of_bool = function
| true -> True
| false -> False
let string_of_tbool = function
| True -> "true"
| False -> "false"
| Maybe -> "maybe"
(* infinities *)
(* ********** *)
type 'a inf =
| Finite of 'a
| INF (* +oo *)
| MINF (* -oo *)
(* see Intinf for operators on Int.t inf *)
(* bot *)
(* *** *)
type 'a bot = Bot | Nb of 'a
let strict_bot f x =
match x with Bot -> Bot | Nb x -> f x
let lift_bot f x =
match x with Bot -> Bot | Nb x -> Nb (f x)
let merge_bot2 x y =
match x,y with Bot,_ | _,Bot -> Bot | Nb a, Nb b -> Nb (a,b)
let join_bot2 f x y =
match x,y with Bot,a | a,Bot -> a | Nb a,Nb b -> Nb (f a b)
exception Bot_found
let debot =
function Nb x -> x | Bot -> raise Bot_found
let rebot f x =
try f x with Bot_found -> Bot
let bot_to_string f = function Bot -> "_|_" | Nb x -> f x