Skip to content

Commit ea6b280

Browse files
committed
a few more functions.
1 parent 839d5b6 commit ea6b280

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

theories/Data/List.v

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Section EqDec.
5858
Qed.
5959
End EqDec.
6060

61+
(* Specialized induction rules *)
6162
Lemma list_ind_singleton
6263
: forall {T : Type} (P : list T -> Prop)
6364
(Hnil : P nil)
@@ -69,6 +70,17 @@ Proof.
6970
destruct ls. eauto. eauto.
7071
Qed.
7172

73+
Lemma list_rev_ind
74+
: forall T (P : list T -> Prop),
75+
P nil ->
76+
(forall l ls, P ls -> P (ls ++ l :: nil)) ->
77+
forall ls, P ls.
78+
Proof.
79+
clear. intros. rewrite <- rev_involutive.
80+
induction (rev ls).
81+
apply H.
82+
simpl. auto.
83+
Qed.
7284

7385
Section AllB.
7486
Variable T : Type.

theories/Data/Nat.v

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,9 @@ Global Instance Injective_S (a b : nat) : Injective (S a = S b) :=
107107
}.
108108
abstract (inversion 1; auto).
109109
Defined.
110+
111+
Definition nat_get_eq (n m : nat) (pf : unit -> n = m) : n = m :=
112+
match PeanoNat.Nat.eq_dec n m with
113+
| left pf => pf
114+
| right bad => match bad (pf tt) with end
115+
end.

theories/Data/PList.v

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Require Import ExtLib.Structures.Functor.
22
Require Import ExtLib.Structures.Applicative.
33
Require Import ExtLib.Data.POption.
44

5-
Set Printing Universes.
5+
Set Universe Polymorphism.
66

77
Section plist.
88
Polymorphic Universe i.
@@ -24,7 +24,6 @@ Section plist.
2424
| pcons l ls => pcons l (app ls ls')
2525
end.
2626

27-
2827
Polymorphic Definition hd (ls : plist) : poption T :=
2928
match ls with
3029
| pnil => pNone
@@ -55,6 +54,13 @@ Section plist.
5554
| pcons l ls0 => if p l then anyb p ls0 else false
5655
end.
5756

57+
Polymorphic Fixpoint nth_error (ls : plist) (n : nat) : poption T :=
58+
match n , ls with
59+
| 0 , pcons l _ => pSome l
60+
| S n , pcons _ ls => nth_error ls n
61+
| _ , _ => pNone
62+
end.
63+
5864
Section folds.
5965
Polymorphic Universe j.
6066
Context {U : Type@{j}}.
@@ -80,6 +86,9 @@ Arguments pcons {_} _ _.
8086
Arguments pIn {_} _ _.
8187
Arguments anyb {_} _ _.
8288
Arguments allb {_} _ _.
89+
Arguments fold_left {_ _} _ _ _.
90+
Arguments fold_right {_ _} _ _ _.
91+
Arguments nth_error {_} _ _.
8392

8493
Section pmap.
8594
Polymorphic Universe i j.

0 commit comments

Comments
 (0)