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