aboutsummaryrefslogtreecommitdiff
path: root/src/Util/Tuple.v
diff options
context:
space:
mode:
authorGravatar jadep <jade.philipoom@gmail.com>2016-07-08 09:52:29 -0400
committerGravatar jadep <jade.philipoom@gmail.com>2016-07-08 10:14:25 -0400
commit4028538d1ea1d85f0827ce90fe66a953c033143e (patch)
tree1dc65911e92ed4a841b8a5efcc2c9c88c02b4bf8 /src/Util/Tuple.v
parent5a0c4eb34708d2c85d91e6cb2c708ed16249e06d (diff)
Util/Tuple: added a version of from_list that doesn't require a proof of length equality
Diffstat (limited to 'src/Util/Tuple.v')
-rw-r--r--src/Util/Tuple.v33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/Util/Tuple.v b/src/Util/Tuple.v
index 3dfbf6bab..4232c7bf8 100644
--- a/src/Util/Tuple.v
+++ b/src/Util/Tuple.v
@@ -142,3 +142,36 @@ Global Instance dec_fieldwise {A RA} {HA : DecidableRel RA} {n} : DecidableRel (
Proof.
destruct n; unfold fieldwise; exact _.
Qed.
+
+Fixpoint from_list_default' {T} (d y:T) (n:nat) (xs:list T) : tuple' T n :=
+ match n return tuple' T n with
+ | 0 => y (* ignore high digits *)
+ | S n' =>
+ match xs return _ with
+ | cons x xs' => (from_list_default' d x n' xs', y)
+ | nil => (from_list_default' d d n' nil, y)
+ end
+ end.
+
+Definition from_list_default {T} d (n:nat) (xs:list T) : tuple T n :=
+match n return tuple T n with
+| 0 => tt
+| S n' =>
+ match xs return _ with
+ | cons x xs' => (from_list_default' d x n' xs')
+ | nil => (from_list_default' d d n' nil)
+ end
+end.
+
+Lemma from_list_default'_eq : forall {T} (d : T) xs n y pf,
+ from_list_default' d y n xs = from_list' y n xs pf.
+Proof.
+ induction xs; destruct n; intros; simpl in *; congruence.
+Qed.
+
+Lemma from_list_default_eq : forall {T} (d : T) xs n pf,
+ from_list_default d n xs = from_list n xs pf.
+Proof.
+ induction xs; destruct n; intros; try solve [simpl in *; congruence].
+ apply from_list_default'_eq.
+Qed.