-
Notifications
You must be signed in to change notification settings - Fork 1
/
ListContext.v
72 lines (56 loc) · 1.74 KB
/
ListContext.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Require Import Monad.
Require Import NCM.
Require Import List.
Require Import Orders.
Require Import Mergesort.
Require Import Arith.
Import ListNotations.
Variable A : Type.
Variable a1 a2 a3: A.
Module FinMapOrder <: TotalLeBool.
Definition t := nat * A.
Fixpoint leb (x y : t) := let (m,_) := x in
let (n,_) := y in
(m <=? n)%nat.
Infix "<=?" := leb (at level 70).
Theorem leb_total : forall a1 a2, (a1 <=? a2 =true) \/ (a2 <=? a1 = true).
Proof.
intros [a1] [a2].
simpl.
rewrite 2 Nat.leb_le.
apply Nat.le_ge_cases.
Qed.
End FinMapOrder.
Module Import FinMapSort := Sort FinMapOrder.
Section ListContext.
Set Implicit Arguments.
Definition FinMap := list (nat * A).
Definition ListContext := option FinMap.
Eval compute in (sort [(1,a1); (3,a3); (0,a2); (2,a1)]%nat).
(* TODO: Disjoint merge that also sorts the inputs *)
Definition mergeListContext' (ls1 ls2 : FinMap) : ListContext.
Admitted.
Definition mergeListContext (ls1 ls2 : ListContext) : ListContext :=
match ls1, ls2 with
| Some ls1', Some ls2' => mergeListContext' ls1' ls2'
| _, _ => None
end.
Definition singleton (x : nat) (a : A) : ListContext :=
Some ((x,a) :: nil).
Instance NCM_ListContext : NCM ListContext :=
{ one := Some nil
; zero := None
; m := mergeListContext
; base := fun b => exists x a, b = singleton x a}.
Opaque base.
Lemma singleton_base : forall x a, base (singleton x a).
Proof. intros. exists x. exists a. reflexivity. Defined.
Hint Resolve singleton_base.
(* TODO: laws *)
Instance NCM_ListContext_Laws : NCM_Laws ListContext.
Admitted.
Example test : forall (x : nat) (a : A), singleton x a ∙ singleton x a = 0.
Proof.
intros. reification.
Defined.
End ListContext.