Skip to content

Commit

Permalink
a few more functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmalecha committed Feb 11, 2016
1 parent 839d5b6 commit ea6b280
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
12 changes: 12 additions & 0 deletions theories/Data/List.v
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Section EqDec.
Qed.
End EqDec.

(* Specialized induction rules *)
Lemma list_ind_singleton
: forall {T : Type} (P : list T -> Prop)
(Hnil : P nil)
Expand All @@ -69,6 +70,17 @@ Proof.
destruct ls. eauto. eauto.
Qed.

Lemma list_rev_ind
: forall T (P : list T -> Prop),
P nil ->
(forall l ls, P ls -> P (ls ++ l :: nil)) ->
forall ls, P ls.
Proof.
clear. intros. rewrite <- rev_involutive.
induction (rev ls).
apply H.
simpl. auto.
Qed.

Section AllB.
Variable T : Type.
Expand Down
6 changes: 6 additions & 0 deletions theories/Data/Nat.v
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,9 @@ Global Instance Injective_S (a b : nat) : Injective (S a = S b) :=
}.
abstract (inversion 1; auto).
Defined.

Definition nat_get_eq (n m : nat) (pf : unit -> n = m) : n = m :=
match PeanoNat.Nat.eq_dec n m with
| left pf => pf
| right bad => match bad (pf tt) with end
end.
13 changes: 11 additions & 2 deletions theories/Data/PList.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Require Import ExtLib.Structures.Functor.
Require Import ExtLib.Structures.Applicative.
Require Import ExtLib.Data.POption.

Set Printing Universes.
Set Universe Polymorphism.

Section plist.
Polymorphic Universe i.
Expand All @@ -24,7 +24,6 @@ Section plist.
| pcons l ls => pcons l (app ls ls')
end.


Polymorphic Definition hd (ls : plist) : poption T :=
match ls with
| pnil => pNone
Expand Down Expand Up @@ -55,6 +54,13 @@ Section plist.
| pcons l ls0 => if p l then anyb p ls0 else false
end.

Polymorphic Fixpoint nth_error (ls : plist) (n : nat) : poption T :=
match n , ls with
| 0 , pcons l _ => pSome l
| S n , pcons _ ls => nth_error ls n
| _ , _ => pNone
end.

Section folds.
Polymorphic Universe j.
Context {U : Type@{j}}.
Expand All @@ -80,6 +86,9 @@ Arguments pcons {_} _ _.
Arguments pIn {_} _ _.
Arguments anyb {_} _ _.
Arguments allb {_} _ _.
Arguments fold_left {_ _} _ _ _.
Arguments fold_right {_ _} _ _ _.
Arguments nth_error {_} _ _.

Section pmap.
Polymorphic Universe i j.
Expand Down

0 comments on commit ea6b280

Please sign in to comment.