Skip to content

Commit 6d50ea7

Browse files
committed
Add Coq definitions for Tuple and {head,tail,cons}Tuple functions.
These still need to be associated with the corresponding SAW primitives in `Translation/Coq/SpecialTreatment.hs`. Note that the definitions also expect the SAW type `TypeList` to be translated to `list Type` in Coq.
1 parent aa624a8 commit 6d50ea7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

saw-core-coq/coq/handwritten/CryptolToCoq/SAWCoreScaffolding.v

+36
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,42 @@ Instance Inhabited_Intro (a:Type) (b:a -> Type) (Hb: forall x, Inhabited (b x))
4242
Global Hint Extern 5 (Inhabited ?A) =>
4343
(apply (@MkInhabited A); intuition (eauto with typeclass_instances inh)) : typeclass_instances.
4444

45+
Fixpoint TupleApp (a : Type) (ts : list Type) : Type :=
46+
match ts with
47+
| nil => a
48+
| cons t ts' => TupleApp (prod a t) ts'
49+
end.
50+
51+
Definition Tuple (ts : list Type) : Type :=
52+
match ts with
53+
| nil => unit
54+
| cons t ts' => TupleApp t ts'
55+
end.
56+
57+
Fixpoint headTuple {a : Type} {ts : TypeList} : Tuple (cons a ts) -> a :=
58+
match ts with
59+
| nil => @id a
60+
| cons t ts' => compose fst (@headTuple (a * t) ts')
61+
end.
62+
63+
Fixpoint mapTupleApp {a b : Type} {ts : list Type} (f : a -> b) : TupleApp a ts -> TupleApp b ts :=
64+
match ts with
65+
| nil => f
66+
| cons t ts' => @mapTupleApp (a * t) (b * t) ts' (fun x => (f (fst x), snd x))
67+
end.
68+
69+
Definition tailTuple {a : Type} {ts : list Type} : Tuple (cons a ts) -> Tuple ts :=
70+
match ts with
71+
| nil => (fun _ : a => tt)
72+
| cons t ts' => @mapTupleApp (a * t) t ts' snd
73+
end.
74+
75+
Definition consTuple {a : Type} {ts : list Type} (x : a) : Tuple ts -> Tuple (cons a ts) :=
76+
match ts with
77+
| nil => (fun _ : unit => x)
78+
| cons t ts' => @mapTupleApp t (a * t) ts' (pair x)
79+
end.
80+
4581
Definition String := String.string.
4682

4783
Instance Inhabited_String : Inhabited String :=

0 commit comments

Comments
 (0)