minor cleanups, deleted dead code, eliminated use of (==) on CoreType
[coq-hetmet.git] / src / HaskCoreTypes.v
1 (*********************************************************************************************************************************)
2 (* HaskCoreTypes: basically GHC's TypeRep.Type imported into Coqland                                                             *)
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 HaskCoreVars.
12
13 Variable CoreTyCon           : Type.                      Extract Inlined Constant CoreTyCon             => "TyCon.TyCon".
14 Variable CoreDataCon         : Type.                      Extract Inlined Constant CoreDataCon           => "DataCon.DataCon".
15 Variable CoreName            : Type.                      Extract Inlined Constant CoreName              => "Name.Name".
16 Variable CoreCoercion        : Type.                      Extract Inlined Constant CoreCoercion          => "Coercion.Coercion".
17 Variable Class_              : Type.                      Extract Inlined Constant Class_                => "Class.Class".
18 Variable classTyCon          : Class_ -> CoreTyCon.       Extract Inlined Constant classTyCon            => "Class.classTyCon".
19 Variable tyConToString       : CoreTyCon      -> string.  Extract Inlined Constant tyConToString         => "outputableToString".
20 Variable dataConToString     : CoreDataCon-> string.      Extract Inlined Constant dataConToString       => "outputableToString".
21 Variable CoreIPName          : Type -> Type.
22
23    Extract Constant CoreIPName "’a"        => "BasicTypes.IPName".
24    Extraction Inline CoreIPName.
25
26 (* this exracts onto TypeRep.Type, on the nose *)
27 Inductive CoreType :=
28 | TyVarTy  : CoreVar                    -> CoreType
29 | AppTy    : CoreType  ->      CoreType -> CoreType   (* first arg must be AppTy or TyVarTy*)
30 | TyConApp : CoreTyCon -> list CoreType -> CoreType
31 | FunTy    : CoreType  ->      CoreType -> CoreType   (* technically redundant since we have FunTyCon *)
32 | ForAllTy : CoreVar   ->      CoreType -> CoreType
33 | PredTy   : PredType                   -> CoreType
34 with PredType :=
35 | ClassP   : Class_              -> list CoreType -> PredType
36 | IParam   : CoreIPName CoreName -> CoreType      -> PredType
37 | EqPred   : CoreType            -> CoreType      -> PredType.
38 Extract Inductive CoreType =>
39    "TypeRep.Type" [ "TypeRep.TyVarTy" "TypeRep.AppTy" "TypeRep.TyConApp" "TypeRep.FunTy" "TypeRep.ForAllTy" "TypeRep.PredTy" ].
40 Extract Inductive PredType =>
41    "TypeRep.PredType" [ "TypeRep.ClassP" "TypeRep.IParam" "TypeRep.EqPred" ].
42
43 Variable coreNameToString      : CoreName     -> string.    Extract Inlined Constant coreNameToString       => "outputableToString".
44 Variable coreCoercionToString  : CoreCoercion -> string.    Extract Inlined Constant coreCoercionToString   => "outputableToString".
45 Variable coreCoercionKind : CoreCoercion -> CoreType*CoreType. Extract Inlined Constant coreCoercionKind => "Coercion.coercionKind".
46 Variable kindOfCoreType   : CoreType -> Kind.   Extract Inlined Constant kindOfCoreType   => "(coreKindToKind . Coercion.typeKind)".
47 Variable coreTypeToString : CoreType -> string. Extract Inlined Constant coreTypeToString => "(outputableToString . coreViewDeep)".
48
49 (* once again, we pull the trick of having multiple Coq types map to a single Haskell type to provide stronger typing *)
50 Variable TyCon           : Type.                         Extract Inlined Constant TyCon             => "TyCon.TyCon".
51 Variable TyFun           : Type.                         Extract Inlined Constant TyFun             => "TyCon.TyCon".
52
53 (* GHC provides decision procedures for equality on its primitive types; we tell Coq to blindly trust them *)
54 Variable coreTyCon_eq        : EqDecider CoreTyCon.       Extract Inlined Constant coreTyCon_eq          => "(==)".
55 Variable tyCon_eq            : EqDecider TyCon.           Extract Inlined Constant tyCon_eq              => "(==)".
56 Variable tyFun_eq            : EqDecider TyFun.           Extract Inlined Constant tyFun_eq              => "(==)".
57 Variable dataCon_eq          : EqDecider CoreDataCon.     Extract Inlined Constant dataCon_eq            => "(==)".
58 Variable coreName_eq         : EqDecider CoreName.        Extract Inlined Constant coreName_eq           => "(==)".
59 Instance CoreTyConEqDecidable: EqDecidable CoreTyCon   := { eqd_dec := coreTyCon_eq }.
60 Instance TyConEqDecidable    : EqDecidable TyCon       := { eqd_dec := tyCon_eq }.
61 Instance TyFunEqDecidable    : EqDecidable TyFun       := { eqd_dec := tyFun_eq }.
62 Instance DataConEqDecidable  : EqDecidable CoreDataCon := { eqd_dec := dataCon_eq }.
63 Instance CoreNameEqDecidable : EqDecidable CoreName    := { eqd_dec := coreName_eq }.
64
65
66
67 Instance CoreTypeToString : ToString CoreType := { toString := coreTypeToString }.
68 Instance CoreNameToString : ToString CoreName := { toString := coreNameToString }.
69 Instance CoreCoercionToString : ToString CoreCoercion := { toString := coreCoercionToString }.
70 Instance CoreDataConToString : ToString CoreDataCon := { toString := dataConToString }.
71 Instance CoreTyConToString : ToString CoreTyCon := { toString := tyConToString }.