reshuffle definitions in an attempt to iron out inter-file dependenceies
[coq-hetmet.git] / src / HaskWeakVars.v
1 (*********************************************************************************************************************************)
2 (* HaskWeakVars: types and variables for HaskWeak                                                                               *)
3 (*********************************************************************************************************************************)
4
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 HaskKinds.
11 Require Import HaskLiteralsAndTyCons.
12 Require Import HaskCoreVars.
13 Require Import HaskCoreTypes.
14 Require Import HaskWeakTypes.
15
16 (* a WeakExprVar just wraps a CoreVar and tags it with the type of its value *)
17 Inductive WeakExprVar := weakExprVar : CoreVar -> WeakType -> WeakExprVar.
18
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.
27
28 Definition weakTypeVarToKind (tv:WeakTypeVar) : Kind :=
29   match tv with weakTypeVar _ k => k end.
30   Coercion weakTypeVarToKind : WeakTypeVar >-> Kind.
31
32 Definition weakVarToCoreVar (wv:WeakVar) : CoreVar :=
33   match wv with
34   | WExprVar (weakExprVar v _    ) => v
35   | WTypeVar (weakTypeVar v _    ) => v
36   | WCoerVar (weakCoerVar v _ _ _) => v
37  end.
38  Coercion weakVarToCoreVar : WeakVar >-> CoreVar.
39
40 Definition haskLiteralToWeakType lit : WeakType :=
41   WTyCon (haskLiteralToTyCon lit).
42   Coercion haskLiteralToWeakType : HaskLiteral >-> WeakType.
43
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   General.filter (map (fun x => match coreVarToWeakVar x with WTypeVar v => Some v | _ => None end) (getTyConTyVars_ tc)).
48   Opaque tyConTyVars.
49 Definition tyConKind (tc:TyCon) : list Kind := map (fun (x:WeakTypeVar) => x:Kind) (tyConTyVars tc).
50
51 Variable rawTyFunKind : CoreTyCon -> Kind. Extract Inlined Constant rawTyFunKind => "(coreKindToKind . TyCon.tyConKind)".
52
53 Definition tyFunKind (tc:TyFun) : ((list Kind) * Kind) :=
54   splitKind (rawTyFunKind tc).
55
56 Instance WeakVarToString : ToString WeakVar :=
57   { toString := fun x => toString (weakVarToCoreVar x) }.