ReificationsIsomorphicToGeneralizedArrows: use EqDep
[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 Require Import HaskLiteralsAndTyCons.
13
14 Variable CoreCoercion        : Type.                      Extract Inlined Constant CoreCoercion          => "Coercion.Coercion".
15 Variable classTyCon          : Class_ -> CoreTyCon.       Extract Inlined Constant classTyCon            => "Class.classTyCon".
16 Variable coreTyConToString   : CoreTyCon   -> string.     Extract Inlined Constant coreTyConToString     => "outputableToString".
17 Variable coreDataConToString : CoreDataCon -> string.     Extract Inlined Constant coreDataConToString   => "outputableToString".
18
19 (* this exracts onto TypeRep.Type, on the nose *)
20 Inductive CoreType :=
21 | TyVarTy  : CoreVar                    -> CoreType
22 | AppTy    : CoreType  ->      CoreType -> CoreType   (* first arg must be AppTy or TyVarTy*)
23 | TyConApp : CoreTyCon -> list CoreType -> CoreType
24 | FunTy    : CoreType  ->      CoreType -> CoreType   (* technically redundant since we have FunTyCon *)
25 | ForAllTy : CoreVar   ->      CoreType -> CoreType
26 | PredTy   : PredType                   -> CoreType
27 with PredType :=
28 | ClassP   : Class_              -> list CoreType -> PredType
29 | IParam   : CoreIPName CoreName -> CoreType      -> PredType
30 | EqPred   : CoreType            -> CoreType      -> PredType.
31 Extract Inductive CoreType =>
32    "TypeRep.Type" [ "TypeRep.TyVarTy" "TypeRep.AppTy" "TypeRep.TyConApp" "TypeRep.FunTy" "TypeRep.ForAllTy" "TypeRep.PredTy" ].
33 Extract Inductive PredType =>
34    "TypeRep.PredType" [ "TypeRep.ClassP" "TypeRep.IParam" "TypeRep.EqPred" ].
35
36 Variable coreNameToString      : CoreName     -> string.    Extract Inlined Constant coreNameToString       => "outputableToString".
37 Variable coreCoercionToString  : CoreCoercion -> string.    Extract Inlined Constant coreCoercionToString   => "outputableToString".
38 Variable coreCoercionKind : CoreCoercion -> CoreType*CoreType. Extract Inlined Constant coreCoercionKind => "Coercion.coercionKind".
39 Variable kindOfCoreType   : CoreType -> Kind.   Extract Inlined Constant kindOfCoreType   => "(coreKindToKind . Coercion.typeKind)".
40 Variable coreTypeToString : CoreType -> string. Extract Inlined Constant coreTypeToString => "(outputableToString . coreViewDeep)".
41
42 (* GHC provides decision procedures for equality on its primitive types; we tell Coq to blindly trust them *)
43 Variable coreTyCon_eq         : EqDecider CoreTyCon.       Extract Inlined Constant coreTyCon_eq          => "(==)".
44 Variable tyCon_eq             : EqDecider TyCon.           Extract Inlined Constant tyCon_eq              => "(==)".
45 Variable tyFun_eq             : EqDecider TyFun.           Extract Inlined Constant tyFun_eq              => "(==)".
46 Variable dataCon_eq           : EqDecider CoreDataCon.     Extract Inlined Constant dataCon_eq            => "(==)".
47 Variable coreName_eq          : EqDecider CoreName.        Extract Inlined Constant coreName_eq           => "(==)".
48 Instance CoreTyConEqDecidable : EqDecidable CoreTyCon   := { eqd_dec := coreTyCon_eq }.
49 Instance TyConEqDecidable     : EqDecidable TyCon       := { eqd_dec := tyCon_eq }.
50 Instance TyFunEqDecidable     : EqDecidable TyFun       := { eqd_dec := tyFun_eq }.
51 Instance DataConEqDecidable   : EqDecidable CoreDataCon := { eqd_dec := dataCon_eq }.
52 Instance CoreNameEqDecidable  : EqDecidable CoreName    := { eqd_dec := coreName_eq }.
53 Instance CoreTypeToString     : ToString CoreType       := { toString := coreTypeToString }.
54 Instance CoreNameToString     : ToString CoreName       := { toString := coreNameToString }.
55 Instance CoreCoercionToString : ToString CoreCoercion   := { toString := coreCoercionToString }.
56 Instance CoreDataConToString  : ToString CoreDataCon    := { toString := coreDataConToString }.
57 Instance CoreTyConToString    : ToString CoreTyCon      := { toString := coreTyConToString }.
58