X-Git-Url: http://git.megacz.com/?p=coq-hetmet.git;a=blobdiff_plain;f=src%2FHaskWeakVars.v;h=51690462a1393bf3a1e10ae39d07ccabede3a9fc;hp=782c2a2c8cbf5708b8e82c9abd61552dc5264908;hb=d69d4c8660d8f1f3ea13868c2e2d1c7f8a4d68f7;hpb=bcb16a7fa1ff772f12807c4587609fd756b7762e diff --git a/src/HaskWeakVars.v b/src/HaskWeakVars.v index 782c2a2..5169046 100644 --- a/src/HaskWeakVars.v +++ b/src/HaskWeakVars.v @@ -4,21 +4,15 @@ Generalizable All Variables. Require Import Preamble. -Require Import General. Require Import Coq.Strings.String. Require Import Coq.Lists.List. +Require Import General. Require Import HaskKinds. -Require Import HaskCoreLiterals. +Require Import HaskLiteralsAndTyCons. Require Import HaskCoreVars. Require Import HaskCoreTypes. Require Import HaskWeakTypes. -(* TO DO: finish this *) -Inductive WeakCoercion : Type := weakCoercion : WeakType -> WeakType -> CoreCoercion -> WeakCoercion. - -(* a WeakCoerVar just wraps a CoreVar and tags it with the pair of types amongst which it coerces *) -Inductive WeakCoerVar := weakCoerVar : CoreVar -> WeakType -> WeakType -> WeakCoerVar. - (* a WeakExprVar just wraps a CoreVar and tags it with the type of its value *) Inductive WeakExprVar := weakExprVar : CoreVar -> WeakType -> WeakExprVar. @@ -37,9 +31,9 @@ Definition weakTypeVarToKind (tv:WeakTypeVar) : Kind := Definition weakVarToCoreVar (wv:WeakVar) : CoreVar := match wv with - | WExprVar (weakExprVar v _ ) => v - | WTypeVar (weakTypeVar v _ ) => v - | WCoerVar (weakCoerVar v _ _ ) => v + | WExprVar (weakExprVar v _ ) => v + | WTypeVar (weakTypeVar v _ ) => v + | WCoerVar (weakCoerVar v _ _ _) => v end. Coercion weakVarToCoreVar : WeakVar >-> CoreVar. @@ -47,41 +41,17 @@ Definition haskLiteralToWeakType lit : WeakType := WTyCon (haskLiteralToTyCon lit). Coercion haskLiteralToWeakType : HaskLiteral >-> WeakType. -(* EqDecidable instances for all of the above *) -Instance WeakCoerVarEqDecidable : EqDecidable WeakCoerVar. - apply Build_EqDecidable. - intros. - destruct v1 as [cv1 t1a t1b]. - destruct v2 as [cv2 t2a t2b]. - destruct (eqd_dec cv1 cv2); subst. - destruct (eqd_dec t1a t2a); subst. - destruct (eqd_dec t1b t2b); subst. - left; auto. - right; intro; apply n; inversion H; subst; auto. - right; intro; apply n; inversion H; subst; auto. - right; intro; apply n; inversion H; subst; auto. - Defined. +Variable coreVarToWeakVar : CoreVar -> WeakVar. Extract Inlined Constant coreVarToWeakVar => "coreVarToWeakVar". +Variable getTyConTyVars_ : CoreTyCon -> list CoreVar. Extract Inlined Constant getTyConTyVars_ => "getTyConTyVars". +Definition tyConTyVars (tc:CoreTyCon) := + filter (map (fun x => match coreVarToWeakVar x with WTypeVar v => Some v | _ => None end) (getTyConTyVars_ tc)). + Opaque tyConTyVars. +Definition tyConKind (tc:TyCon) : list Kind := map (fun (x:WeakTypeVar) => x:Kind) (tyConTyVars tc). + +Variable rawTyFunKind : CoreTyCon -> Kind. Extract Inlined Constant rawTyFunKind => "(coreKindToKind . TyCon.tyConKind)". -Instance WeakExprVarEqDecidable : EqDecidable WeakExprVar. - apply Build_EqDecidable. - intros. - destruct v1 as [cv1 k1]. - destruct v2 as [cv2 k2]. - destruct (eqd_dec cv1 cv2); subst. - destruct (eqd_dec k1 k2); subst. - left; auto. - right; intro; apply n; inversion H; subst; auto. - right; intro; apply n; inversion H; subst; auto. - Defined. +Definition tyFunKind (tc:TyFun) : ((list Kind) * Kind) := + splitKind (rawTyFunKind tc). -Instance WeakVarEqDecidable : EqDecidable WeakVar. - apply Build_EqDecidable. - induction v1; destruct v2; try (right; intro q; inversion q; fail) ; auto; - destruct (eqd_dec w w0); subst. - left; auto. - right; intro X; apply n; inversion X; auto. - left; auto. - right; intro X; apply n; inversion X; auto. - left; auto. - right; intro X; apply n; inversion X; auto. - Defined. +Instance WeakVarToString : ToString WeakVar := + { toString := fun x => toString (weakVarToCoreVar x) }.