add new Where rule, eliminate unnecessary ga_swaps in the Skolemizer
[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 Coq.Strings.String.
8 Require Import Coq.Lists.List.
9 Require Import General.
10 Require Import HaskKinds.
11 Require Import HaskLiterals.
12 Require Import HaskTyCons.
13 Require Import HaskCoreVars.
14 Require Import HaskCoreTypes.
15 Require Import HaskWeakTypes.
16
17 (* a WeakExprVar just wraps a CoreVar and tags it with the type of its value *)
18 Inductive WeakExprVar := weakExprVar : CoreVar -> WeakType -> WeakExprVar.
19
20 (* a WeakVar is one of the three sorts *)
21 Inductive WeakVar : Type :=
22 | WExprVar : WeakExprVar -> WeakVar
23 | WTypeVar : WeakTypeVar -> WeakVar
24 | WCoerVar : WeakCoerVar -> WeakVar.
25   Coercion WExprVar : WeakExprVar >-> WeakVar.
26   Coercion WTypeVar : WeakTypeVar >-> WeakVar.
27   Coercion WCoerVar : WeakCoerVar >-> WeakVar.
28
29 Definition weakTypeVarToKind (tv:WeakTypeVar) : Kind :=
30   match tv with weakTypeVar _ k => k end.
31   Coercion weakTypeVarToKind : WeakTypeVar >-> Kind.
32
33 Definition weakVarToCoreVar (wv:WeakVar) : CoreVar :=
34   match wv with
35   | WExprVar (weakExprVar v _  ) => v
36   | WTypeVar (weakTypeVar v _  ) => v
37   | WCoerVar (weakCoerVar v _ _) => v
38  end.
39  Coercion weakVarToCoreVar : WeakVar >-> CoreVar.
40
41 Definition haskLiteralToWeakType lit : WeakType :=
42   WTyCon (haskLiteralToTyCon lit).
43   Coercion haskLiteralToWeakType : HaskLiteral >-> WeakType.
44
45 Variable coreVarToWeakVar  : CoreVar  -> WeakVar.   Extract Inlined Constant coreVarToWeakVar    => "coreVarToWeakVar".
46 Variable getTyConTyVars_   : CoreTyCon   -> list CoreVar.  Extract Inlined Constant getTyConTyVars_   => "getTyConTyVars".
47 Definition tyConTyVars (tc:CoreTyCon) :=
48   filter (map (fun x => match coreVarToWeakVar x with WTypeVar v => Some v | _ => None end) (getTyConTyVars_ tc)).
49   Opaque tyConTyVars.
50 Definition tyConKind (tc:TyCon) : list Kind := map (fun (x:WeakTypeVar) => x:Kind) (tyConTyVars tc).
51
52 Variable rawTyFunKind : CoreTyCon -> ((list Kind) * Kind). Extract Inlined Constant rawTyFunKind => "rawTyFunKind".
53
54 Definition tyFunKind (tc:TyFun) : ((list Kind) * Kind) :=
55   rawTyFunKind tc.
56
57 Instance WeakVarToString : ToString WeakVar :=
58   { toString := fun x => toString (weakVarToCoreVar x) }.