-
Notifications
You must be signed in to change notification settings - Fork 1
/
DiffLists.v
51 lines (42 loc) · 1.06 KB
/
DiffLists.v
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
Require Import Coq.Lists.List.
Require Import FunctionalExtensionality.
Import ListNotations.
Require Import Coq.Logic.ProofIrrelevance.
Require Import Coq.Logic.ProofIrrelevanceFacts.
Set Implicit Arguments.
Module dlist.
Definition t' A := list A -> list A.
Definition prepender A (f : t' A) : Prop :=
exists lf, forall l, f l = lf ++ l.
Definition t A := {f : t' A | prepender f}.
Definition toList A (d : t A) : list A := proj1_sig d [].
Definition fromList A (l : list A) : t A.
refine (exist _ (app l) _).
red.
eauto.
Defined.
Theorem from_to_id :
forall (a : Set) (xs : list a),
toList (fromList xs) = xs.
Proof.
unfold toList, fromList.
simpl.
intros.
now rewrite app_nil_r.
Qed.
Theorem to_from_id :
forall (a : Set) (xs : t a),
fromList (toList xs) = xs.
Proof.
destruct xs as [f [l H]].
unfold fromList, toList.
simpl.
apply subset_eq_compat.
apply functional_extensionality.
intros x.
rewrite H.
rewrite H.
rewrite app_ass.
reflexivity.
Qed.
End dlist.