X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=HsTools.hs;h=22cd57f06de9d90350cb2c39e67b90b254ba058d;hb=1d2f36c370db9ef82667741cc9414f9896084af3;hp=967db1880f4d634b657c1931ac9bca3ee3e8890d;hpb=430a309686dbaf585844dc129cf7b6aa8568b652;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git a/HsTools.hs b/HsTools.hs index 967db18..22cd57f 100644 --- a/HsTools.hs +++ b/HsTools.hs @@ -3,7 +3,7 @@ module HsTools where -- Standard modules import qualified Unsafe.Coerce - +import qualified Maybe -- GHC API import qualified GHC @@ -31,6 +31,7 @@ import qualified RnEnv import qualified TcExpr import qualified TcEnv import qualified TcSimplify +import qualified TcTyFuns import qualified Desugar import qualified InstEnv import qualified FamInstEnv @@ -123,17 +124,33 @@ mkId rdr_name = do TcEnv.tcLookupId name return id +normaliseType :: + HscTypes.HscEnv + -> Type.Type + -> IO Type.Type +normaliseType env ty = do + (err, nty) <- MonadUtils.liftIO $ + -- Initialize the typechecker monad + TcRnMonad.initTcPrintErrors env PrelNames.iNTERACTIVE $ do + -- Normalize the type + (_, nty) <- TcTyFuns.tcNormaliseFamInst ty + return nty + let normalized_ty = Maybe.fromJust nty + return normalized_ty + -- | Translate a core Type to an HsType. Far from complete so far. coreToHsType :: Type.Type -> HsTypes.LHsType RdrName.RdrName -- Translate TyConApps -coreToHsType (Type.splitTyConApp_maybe -> Just (tycon, tys)) = - foldl (\t a -> SrcLoc.noLoc $ HsTypes.HsAppTy t a) tycon_ty (map coreToHsType tys) - where - tycon_name = TyCon.tyConName tycon - mod_name = Module.moduleName $ Name.nameModule tycon_name - occ_name = Name.nameOccName tycon_name - tycon_rdrname = RdrName.mkRdrQual mod_name occ_name - tycon_ty = SrcLoc.noLoc $ HsTypes.HsTyVar tycon_rdrname +coreToHsType ty = case Type.splitTyConApp_maybe ty of + Just (tycon, tys) -> + foldl (\t a -> SrcLoc.noLoc $ HsTypes.HsAppTy t a) tycon_ty (map coreToHsType tys) + where + tycon_name = TyCon.tyConName tycon + mod_name = Module.moduleName $ Name.nameModule tycon_name + occ_name = Name.nameOccName tycon_name + tycon_rdrname = RdrName.mkRdrQual mod_name occ_name + tycon_ty = SrcLoc.noLoc $ HsTypes.HsTyVar tycon_rdrname + Nothing -> error $ "HsTools.coreToHsType Cannot translate non-tycon type" -- | Evaluate a CoreExpr and return its value. For this to work, the caller -- should already know the result type for sure, since the result value is