Skip to content

Commit b7c6f75

Browse files
committed
Add more definitions for Stdlib
1 parent 008cb5b commit b7c6f75

File tree

8 files changed

+367
-88
lines changed

8 files changed

+367
-88
lines changed

proofs/Basics.v

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ Definition int64 := Z.
113113

114114
Definition nativeint := Z.
115115

116+
Definition char := ascii.
117+
116118
Definition bytes := string.
117119

118120
Definition try {A : Set} (x : A) : A := x.
@@ -233,58 +235,6 @@ Module Stdlib.
233235
| Lt => -1
234236
| Gt => 1
235237
end.
236-
237-
(** * Boolean operations *)
238-
239-
(** * Composition operators *)
240-
Definition reverse_apply {A B : Type} (x : A) (f : A -> B) : B :=
241-
f x.
242-
243-
(** * Integer arithmetic *)
244-
245-
(** * Bitwise operations *)
246-
247-
(** * Floating-point arithmetic *)
248-
(* TODO *)
249-
250-
(** * String operations *)
251-
252-
(** * Character operations *)
253-
Definition int_of_char (c : ascii) : Z :=
254-
Z.of_nat (nat_of_ascii c).
255-
256-
(** * Unit operations *)
257-
Definition ignore {A : Type} (_ : A) : unit :=
258-
tt.
259-
260-
(** * String conversion functions *)
261-
Definition string_of_bool (b : bool) : string :=
262-
if b then
263-
"true" % string
264-
else
265-
"false" % string.
266-
267-
(* TODO *)
268-
Definition bool_of_string (s : string) : bool :=
269-
false.
270-
271-
(* TODO *)
272-
Definition string_of_int (n : Z) : string :=
273-
"0" % string.
274-
275-
(* TODO *)
276-
Definition int_of_string (s : string) : Z :=
277-
0.
278-
279-
(** * Pair operations *)
280-
281-
(** * List operations *)
282-
(** The concatenation of lists with an implicit parameter. *)
283-
Definition app {A : Type} (l1 l2 : list A) : list A :=
284-
app l1 l2.
285-
286-
(** * Operations on format strings *)
287-
(* TODO *)
288238
End Stdlib.
289239

290240
Module Char.

proofs/List.v

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,49 @@ Require Import Program.Program.
55
Local Open Scope Z_scope.
66
Import ListNotations.
77

8-
Fixpoint length_aux {A : Type} (len : Z) (x : list A) : Z :=
8+
Fixpoint length_aux {A : Set} (len : Z) (x : list A) : Z :=
99
match x with
1010
| [] => len
1111
| cons a l => length_aux (Z.add len 1) l
1212
end.
1313

14-
Definition length {A : Type} (l : list A) : Z := length_aux 0 l.
14+
Definition length {A : Set} (l : list A) : Z := length_aux 0 l.
1515

16-
Lemma length_cons {A : Type} (x : A) (l : list A)
16+
Lemma length_cons {A : Set} (x : A) (l : list A)
1717
: length (x :: l) = length l + 1.
1818
Admitted.
1919

20-
Lemma length_is_pos {A : Type} (l : list A) : 0 <= length l.
20+
Lemma length_is_pos {A : Set} (l : list A) : 0 <= length l.
2121
Admitted.
2222

23-
Definition append {A : Type} : (list A) -> (list A) -> list A :=
24-
Stdlib.app.
23+
Definition append {A : Set} : (list A) -> (list A) -> list A :=
24+
List.app (A := A).
2525

26-
Fixpoint rev_append {A : Type} (l1 : list A) (l2 : list A) : list A :=
26+
Fixpoint rev_append {A : Set} (l1 : list A) (l2 : list A) : list A :=
2727
match l1 with
2828
| [] => l2
2929
| cons a l => rev_append l (cons a l2)
3030
end.
3131

32-
Definition rev {A : Type} (l : list A) : list A := rev_append l [].
32+
Definition rev {A : Set} (l : list A) : list A := rev_append l [].
3333

34-
Fixpoint flatten {A : Type} (x : list (list A)) : list A :=
34+
Fixpoint flatten {A : Set} (x : list (list A)) : list A :=
3535
match x with
3636
| [] => []
37-
| cons l r => Stdlib.app l (flatten r)
37+
| cons l r => List.app l (flatten r)
3838
end.
3939

40-
Definition concat {A : Type} : (list (list A)) -> list A := flatten.
40+
Definition concat {A : Set} : (list (list A)) -> list A := flatten.
4141

42-
Fixpoint map {A B : Type} (f : A -> B) (x : list A) : list B :=
42+
Fixpoint map {A B : Set} (f : A -> B) (x : list A) : list B :=
4343
match x with
4444
| [] => []
4545
| cons a l =>
4646
let r := f a in
4747
cons r (map f l)
4848
end.
4949

50-
Fixpoint mapi_aux {A B : Type} (i : Z) (f : Z -> A -> B) (x : list A)
50+
Fixpoint mapi_aux {A B : Set} (i : Z) (f : Z -> A -> B) (x : list A)
5151
: list B :=
5252
match x with
5353
| [] => []
@@ -56,43 +56,43 @@ Fixpoint mapi_aux {A B : Type} (i : Z) (f : Z -> A -> B) (x : list A)
5656
cons r (mapi_aux (Z.add i 1) f l)
5757
end.
5858

59-
Definition mapi {A B : Type} (f : Z -> A -> B) (l : list A) : list B :=
59+
Definition mapi {A B : Set} (f : Z -> A -> B) (l : list A) : list B :=
6060
mapi_aux 0 f l.
6161

62-
Definition rev_map {A B : Type} (f : A -> B) (l : list A) : list B :=
62+
Definition rev_map {A B : Set} (f : A -> B) (l : list A) : list B :=
6363
let fix rmap_f (accu : list B) (x : list A) : list B :=
6464
match x with
6565
| [] => accu
6666
| cons a l => rmap_f (cons (f a) accu) l
6767
end in
6868
rmap_f [] l.
6969

70-
Fixpoint fold_left {A B : Type} (f : A -> B -> A) (accu : A) (l : list B) : A :=
70+
Fixpoint fold_left {A B : Set} (f : A -> B -> A) (accu : A) (l : list B) : A :=
7171
match l with
7272
| [] => accu
7373
| cons a l => fold_left f (f accu a) l
7474
end.
7575

76-
Fixpoint fold_right {A B : Type} (f : A -> B -> B) (l : list A) (accu : B)
76+
Fixpoint fold_right {A B : Set} (f : A -> B -> B) (l : list A) (accu : B)
7777
: B :=
7878
match l with
7979
| [] => accu
8080
| cons a l => f a (fold_right f l accu)
8181
end.
8282

83-
Fixpoint for_all {A : Type} (p : A -> bool) (x : list A) : bool :=
83+
Fixpoint for_all {A : Set} (p : A -> bool) (x : list A) : bool :=
8484
match x with
8585
| [] => true
8686
| cons a l => andb (p a) (for_all p l)
8787
end.
8888

89-
Fixpoint _exists {A : Type} (p : A -> bool) (x : list A) : bool :=
89+
Fixpoint _exists {A : Set} (p : A -> bool) (x : list A) : bool :=
9090
match x with
9191
| [] => false
9292
| cons a l => orb (p a) (_exists p l)
9393
end.
9494

95-
Fixpoint mem {A : Type} `{EqDec A} (x : A) (l : list A) : bool :=
95+
Fixpoint mem {A : Set} `{EqDec A} (x : A) (l : list A) : bool :=
9696
match l with
9797
| [] => false
9898
| y :: l =>
@@ -102,7 +102,7 @@ Fixpoint mem {A : Type} `{EqDec A} (x : A) (l : list A) : bool :=
102102
mem x l
103103
end.
104104

105-
Definition find_all {A : Type} (p : A -> bool) : (list A) -> list A :=
105+
Definition find_all {A : Set} (p : A -> bool) : (list A) -> list A :=
106106
let fix find (accu : list A) (x : list A) : list A :=
107107
match x with
108108
| [] => rev accu
@@ -114,9 +114,9 @@ Definition find_all {A : Type} (p : A -> bool) : (list A) -> list A :=
114114
end in
115115
find [].
116116

117-
Definition filter {A : Type} : (A -> bool) -> (list A) -> list A := find_all.
117+
Definition filter {A : Set} : (A -> bool) -> (list A) -> list A := find_all.
118118

119-
Definition partition {A : Type} (p : A -> bool) (l : list A)
119+
Definition partition {A : Set} (p : A -> bool) (l : list A)
120120
: (list A) * (list A) :=
121121
let fix part (yes : list A) (no : list A) (x : list A)
122122
: (list A) * (list A) :=
@@ -130,7 +130,7 @@ Definition partition {A : Type} (p : A -> bool) (l : list A)
130130
end in
131131
part [] [] l.
132132

133-
Fixpoint mem_assoc {A B : Type} `{EqDec A} (x : A) (l : list (A * B)) : bool :=
133+
Fixpoint mem_assoc {A B : Set} `{EqDec A} (x : A) (l : list (A * B)) : bool :=
134134
match l with
135135
| [] => false
136136
| (y, v) :: l =>
@@ -140,7 +140,7 @@ Fixpoint mem_assoc {A B : Type} `{EqDec A} (x : A) (l : list (A * B)) : bool :=
140140
mem_assoc x l
141141
end.
142142

143-
Fixpoint remove_assoc {A B : Type} `{EqDec A} (x : A) (l : list (A * B))
143+
Fixpoint remove_assoc {A B : Set} `{EqDec A} (x : A) (l : list (A * B))
144144
: list (A * B) :=
145145
match l with
146146
| [] => l
@@ -151,7 +151,7 @@ Fixpoint remove_assoc {A B : Type} `{EqDec A} (x : A) (l : list (A * B))
151151
remove_assoc x l
152152
end.
153153

154-
Fixpoint split {A B : Type} (x : list (A * B)) : (list A) * (list B) :=
154+
Fixpoint split {A B : Set} (x : list (A * B)) : (list A) * (list B) :=
155155
match x with
156156
| [] => ([], [])
157157
| cons (x, y) l =>
@@ -160,7 +160,7 @@ Fixpoint split {A B : Type} (x : list (A * B)) : (list A) * (list B) :=
160160
end
161161
end.
162162

163-
Fixpoint merge {A : Type} (cmp : A -> A -> Z) (l1 : list A) (l2 : list A)
163+
Fixpoint merge {A : Set} (cmp : A -> A -> Z) (l1 : list A) (l2 : list A)
164164
: list A :=
165165
let fix merge_aux (l2 : list A) : list A :=
166166
match (l1, l2) with

0 commit comments

Comments
 (0)