Skip to content

Commit 04b095a

Browse files
committed
Fixed fieldOf, still need fieldUpdate fixed
1 parent 0cbd669 commit 04b095a

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

RGref/DSL/Fields.v

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,41 @@ Section FieldDemo.
5454
Definition Count2nat (n : DFieldTypes Count) : nat. compute; assumption. Defined.
5555
Definition bool2DField (b : bool) : DFieldTypes Flag. compute; assumption. Defined.
5656
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 => _
6365
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 ;
6572

6673
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
7079
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+
(*
7286
constructor.
7387
(* fieldOf *) intro obj. intro x. destruct obj.
7488
dependent induction x; red; auto.
7589
(* fieldUpdate *) intros obj x v. destruct obj.
7690
dependent induction x; compute [DFieldTypes] in *. exact (mkD v b). exact (mkD n v).
77-
Defined.
91+
Defined.*)
7892
(* Print DAccess. (* <-- that is a terrible term due to dependent induction *) *)
7993
Instance pureD : pure_type D.
8094
Program Example demo {Γ} (r : ref{D|any}[deltaD,deltaD]) : rgref Γ unit Γ :=
@@ -83,7 +97,15 @@ Section FieldDemo.
8397
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)).
8498
intro Hcomp. rewrite Hcomp with (f := F1).
8599
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.
89111
End FieldDemo.

0 commit comments

Comments
 (0)