@@ -54,27 +54,41 @@ Section FieldDemo.
54
54
Definition Count2nat (n : DFieldTypes Count) : nat. compute; assumption. Defined .
55
55
Definition bool2DField (b : bool) : DFieldTypes Flag. compute; assumption. Defined .
56
56
Print nat2DField'.
57
- Instance DAccess : FieldAccess D DFieldTypes.
58
- (* Ideally we'd just directly define, but Coq's pattern matching is weak, so we'll use the refine tactic. :=
59
- { fieldOf := fun obj x => match obj return (DFieldTypes x) with (mkD n b) =>
60
- match x as x return _ with
61
- | F1 _ => _
62
- | FS _ _ => _
57
+ Definition getCount (d:D) := match d with (mkD n b) => n end.
58
+ Definition getFlag (d:D) := match d with (mkD n b) => b end.
59
+ Program Instance DAccess : FieldAccess D DFieldTypes :=
60
+ (* Ideally we'd just directly define, but Coq's pattern matching is weak, so we'll use the refine tactic. := *)
61
+ { fieldOf := fun obj x => (*match obj with (mkD n b) =>
62
+ match x as x in t _ return DFieldTypes _ with
63
+ | F1 f1n => _
64
+ | FS fsn finB => _
63
65
end
64
- end;
66
+ end; *)
67
+ (* match x as y return (x = y -> DFieldTypes x) with *)
68
+ match x as y return DFieldTypes x with
69
+ | F1 f1n => _
70
+ | FS fsn finB => _
71
+ end ;
65
72
66
73
fieldUpdate := fun obj f v =>
67
- match (obj,f) with
68
- | (mkD n b,F1 _) => _
69
- | (mkD n b,FS _ _) => _
74
+ match obj with (mkD n b) =>
75
+ match f as f return D with
76
+ | (F1 f1n) => mkD (_ n) b
77
+ | (FS fsn finB) => mkD n (_ b)
78
+ end
70
79
end
71
- }. *)
80
+ }.
81
+ Next Obligation . compute. induction x. refine (getCount obj). refine (getFlag obj). Defined .
82
+ Next Obligation . compute. induction x. refine (getCount obj). refine (getFlag obj). Defined .
83
+
84
+ Print DAccess.
85
+ (*
72
86
constructor.
73
87
(* fieldOf *) intro obj. intro x. destruct obj.
74
88
dependent induction x; red; auto.
75
89
(* fieldUpdate *) intros obj x v. destruct obj.
76
90
dependent induction x; compute [DFieldTypes] in *. exact (mkD v b). exact (mkD n v).
77
- Defined .
91
+ Defined. *)
78
92
(* Print DAccess. (* <-- that is a terrible term due to dependent induction *) *)
79
93
Instance pureD : pure_type D.
80
94
Program Example demo {Γ} (r : ref{D|any}[deltaD,deltaD]) : rgref Γ unit Γ :=
@@ -83,7 +97,15 @@ Section FieldDemo.
83
97
cut (forall f p1 p2 p3, @eq (DFieldTypes f) (@field_read D D _ _ _ _ _ DFieldTypes _ p1 p2 DAccess r f p3) (@fieldOf D _ DFieldTypes DAccess (@fold D _ deltaD deltaD v) f)).
84
98
intro Hcomp. rewrite Hcomp with (f := F1).
85
99
destruct v. compute [nat2DField Count2nat].
86
- compute. fold plus. rewrite plus_comm.
87
-
88
-
100
+ compute [fieldOf]. unfold DAccess. unfold DAccess_obligation_1. unfold fold.
101
+ unfold pure_fold. unfold getCount. unfold getFlag. unfold const_id_fold.
102
+ compute [t_rec t_rect]. (* Now pretty sure I screwed up the def of fieldUpdate *)
103
+ Check DAccess_obligation_3.
104
+ compute [DAccess_obligation_3].
105
+ compute -[fieldUpdate].
106
+ compute [fieldOf DFieldTypes DAccess DAccess_obligation_1 fold DAccess_obligation_3]. rewrite plus_comm.
107
+ (* At this point we *should* be done, but the use of dependent induction to work around
108
+ Coq's pattern matching has introduced some uses of JMeq to deal with *)
109
+ generalize (@JMeq_eq (t (S (S O))) (@F1 (S O)) (@F1 (S O)) (@JMeq_refl (t (S (S O))) (@F1 (S O)))).
110
+ intro e. elim e.
89
111
End FieldDemo.
0 commit comments