1 (*********************************************************************************************************************************)
2 (* HaskWeakVars: types and variables for HaskWeak *)
3 (*********************************************************************************************************************************)
5 Generalizable All Variables.
6 Require Import Preamble.
7 Require Import General.
8 Require Import Coq.Strings.String.
9 Require Import Coq.Lists.List.
10 Require Import HaskGeneral.
11 Require Import HaskLiterals.
12 Require Import HaskCoreVars.
13 Require Import HaskCoreTypes.
15 Inductive WeakTypeVar := weakTypeVar : CoreVar -> Kind -> WeakTypeVar.
17 Inductive WeakCoercion : Type := weakCoercion : CoreType -> CoreType -> CoreCoercion -> WeakCoercion.
19 Inductive WeakCoerVar := weakCoerVar : CoreVar -> CoreType -> CoreType -> WeakCoerVar.
21 Inductive WeakExprVar := weakExprVar : CoreVar -> CoreType -> WeakExprVar.
23 Inductive WeakVar : Type :=
24 | WExprVar : WeakExprVar -> WeakVar
25 | WTypeVar : WeakTypeVar -> WeakVar
26 | WCoerVar : WeakCoerVar -> WeakVar.
27 Coercion WExprVar : WeakExprVar >-> WeakVar.
28 Coercion WTypeVar : WeakTypeVar >-> WeakVar.
29 Coercion WCoerVar : WeakCoerVar >-> WeakVar.
32 Definition haskLiteralToCoreType lit : CoreType :=
33 TyConApp (haskLiteralToTyCon lit) nil.
35 Definition weakTypeToCoreType (wt:CoreType) : CoreType := wt.
37 Definition weakTypeToString : CoreType -> string :=
38 coreTypeToString ○ weakTypeToCoreType.
40 (* EqDecidable instances for all of the above *)
41 Instance CoreTypeVarEqDecidable : EqDecidable WeakTypeVar.
42 apply Build_EqDecidable.
44 destruct v1 as [cv1 k1].
45 destruct v2 as [cv2 k2].
46 destruct (eqd_dec cv1 cv2); subst.
47 destruct (eqd_dec k1 k2); subst.
49 right; intro; apply n; inversion H; subst; auto.
50 right; intro; apply n; inversion H; subst; auto.
53 Instance WeakCoerVarEqDecidable : EqDecidable WeakCoerVar.
54 apply Build_EqDecidable.
56 destruct v1 as [cv1 t1a t1b].
57 destruct v2 as [cv2 t2a t2b].
58 destruct (eqd_dec cv1 cv2); subst.
59 destruct (eqd_dec t1a t2a); subst.
60 destruct (eqd_dec t1b t2b); subst.
62 right; intro; apply n; inversion H; subst; auto.
63 right; intro; apply n; inversion H; subst; auto.
64 right; intro; apply n; inversion H; subst; auto.
67 Instance WeakExprVarEqDecidable : EqDecidable WeakExprVar.
68 apply Build_EqDecidable.
70 destruct v1 as [cv1 k1].
71 destruct v2 as [cv2 k2].
72 destruct (eqd_dec cv1 cv2); subst.
73 destruct (eqd_dec k1 k2); subst.
75 right; intro; apply n; inversion H; subst; auto.
76 right; intro; apply n; inversion H; subst; auto.
79 Instance WeakVarEqDecidable : EqDecidable WeakVar.
80 apply Build_EqDecidable.
81 induction v1; destruct v2; try (right; intro q; inversion q; fail) ; auto;
82 destruct (eqd_dec w w0); subst.
84 right; intro X; apply n; inversion X; auto.
86 right; intro X; apply n; inversion X; auto.
88 right; intro X; apply n; inversion X; auto.