1 (*********************************************************************************************************************************)
2 (* HaskWeakVars: types and variables for HaskWeak *)
3 (*********************************************************************************************************************************)
5 Generalizable All Variables.
6 Require Import Preamble.
7 Require Import Coq.Strings.String.
8 Require Import Coq.Lists.List.
9 Require Import General.
10 Require Import HaskKinds.
11 Require Import HaskLiteralsAndTyCons.
12 Require Import HaskCoreVars.
13 Require Import HaskCoreTypes.
14 Require Import HaskWeakTypes.
16 (* a WeakExprVar just wraps a CoreVar and tags it with the type of its value *)
17 Inductive WeakExprVar := weakExprVar : CoreVar -> WeakType -> WeakExprVar.
19 (* a WeakVar is one of the three sorts *)
20 Inductive WeakVar : Type :=
21 | WExprVar : WeakExprVar -> WeakVar
22 | WTypeVar : WeakTypeVar -> WeakVar
23 | WCoerVar : WeakCoerVar -> WeakVar.
24 Coercion WExprVar : WeakExprVar >-> WeakVar.
25 Coercion WTypeVar : WeakTypeVar >-> WeakVar.
26 Coercion WCoerVar : WeakCoerVar >-> WeakVar.
28 Definition weakTypeVarToKind (tv:WeakTypeVar) : Kind :=
29 match tv with weakTypeVar _ k => k end.
30 Coercion weakTypeVarToKind : WeakTypeVar >-> Kind.
32 Definition weakVarToCoreVar (wv:WeakVar) : CoreVar :=
34 | WExprVar (weakExprVar v _ ) => v
35 | WTypeVar (weakTypeVar v _ ) => v
36 | WCoerVar (weakCoerVar v _ _ _) => v
38 Coercion weakVarToCoreVar : WeakVar >-> CoreVar.
40 Definition haskLiteralToWeakType lit : WeakType :=
41 WTyCon (haskLiteralToTyCon lit).
42 Coercion haskLiteralToWeakType : HaskLiteral >-> WeakType.
44 Variable coreVarToWeakVar : CoreVar -> WeakVar. Extract Inlined Constant coreVarToWeakVar => "coreVarToWeakVar".
45 Variable getTyConTyVars_ : CoreTyCon -> list CoreVar. Extract Inlined Constant getTyConTyVars_ => "getTyConTyVars".
46 Definition tyConTyVars (tc:CoreTyCon) :=
47 filter (map (fun x => match coreVarToWeakVar x with WTypeVar v => Some v | _ => None end) (getTyConTyVars_ tc)).
49 Definition tyConKind (tc:TyCon) : list Kind := map (fun (x:WeakTypeVar) => x:Kind) (tyConTyVars tc).
51 Variable rawTyFunKind : CoreTyCon -> Kind. Extract Inlined Constant rawTyFunKind => "(coreKindToKind . TyCon.tyConKind)".
53 Definition tyFunKind (tc:TyFun) : ((list Kind) * Kind) :=
54 splitKind (rawTyFunKind tc).
56 Instance WeakVarToString : ToString WeakVar :=
57 { toString := fun x => toString (weakVarToCoreVar x) }.