diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2013-01-22 17:01:30 +0000 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2013-01-22 17:01:30 +0000 |
commit | 2cc42dbb6ff09f4105fe44fe1afe9ac08a140d44 (patch) | |
tree | feb5cf29e0b2664b9b9d2abc55cca64d79d53322 /compiler/main | |
parent | 2ec39c76b9816f76f60076fb52c8038035cd1f7b (diff) | |
download | haskell-2cc42dbb6ff09f4105fe44fe1afe9ac08a140d44.tar.gz |
When printing types in the interactive UI, take account of free variables
Often the types we print are full-generalised, but in fact *kinds* are
not, so we need to use tidyOpenType.
Fixes Trac #7587
Diffstat (limited to 'compiler/main')
-rw-r--r-- | compiler/main/HscMain.hs | 2 | ||||
-rw-r--r-- | compiler/main/InteractiveEval.hs | 1 | ||||
-rw-r--r-- | compiler/main/PprTyThing.hs | 7 |
3 files changed, 9 insertions, 1 deletions
diff --git a/compiler/main/HscMain.hs b/compiler/main/HscMain.hs index 3562f27d5c..2f2b53efba 100644 --- a/compiler/main/HscMain.hs +++ b/compiler/main/HscMain.hs @@ -1614,6 +1614,7 @@ hscImport hsc_env str = runInteractiveHsc hsc_env $ do ptext (sLit "parse error in import declaration") -- | Typecheck an expression (but don't run it) +-- Returns its most general type hscTcExpr :: HscEnv -> String -- ^ The expression -> IO Type @@ -1628,6 +1629,7 @@ hscTcExpr hsc_env0 expr = runInteractiveHsc hsc_env0 $ do (text "not an expression:" <+> quotes (text expr)) -- | Find the kind of a type +-- Currently this does *not* generalise the kinds of the type hscKcType :: HscEnv -> Bool -- ^ Normalise the type diff --git a/compiler/main/InteractiveEval.hs b/compiler/main/InteractiveEval.hs index 7fa156aec3..8d64900c71 100644 --- a/compiler/main/InteractiveEval.hs +++ b/compiler/main/InteractiveEval.hs @@ -972,6 +972,7 @@ parseName str = withSession $ \hsc_env -> do -- Getting the type of an expression -- | Get the type of an expression +-- Returns its most general type exprType :: GhcMonad m => String -> m Type exprType expr = withSession $ \hsc_env -> do ty <- liftIO $ hscTcExpr hsc_env expr diff --git a/compiler/main/PprTyThing.hs b/compiler/main/PprTyThing.hs index 932b46c2f5..a60644155f 100644 --- a/compiler/main/PprTyThing.hs +++ b/compiler/main/PprTyThing.hs @@ -33,6 +33,7 @@ import Coercion( pprCoAxiom ) import HscTypes( tyThingParent_maybe ) import TcType import Name +import VarEnv( emptyTidyEnv ) import StaticFlags( opt_PprStyle_Debug ) import Outputable import FastString @@ -161,8 +162,12 @@ pprTypeForUser print_foralls ty | print_foralls = ppr tidy_ty | otherwise = ppr (mkPhiTy ctxt ty') where - tidy_ty = tidyTopType ty (_, ctxt, ty') = tcSplitSigmaTy tidy_ty + (_, tidy_ty) = tidyOpenType emptyTidyEnv ty + -- Often the types/kinds we print in ghci are fully generalised + -- and have no free variables, but it turns out that we sometimes + -- print un-generalised kinds (eg when doing :k T), so it's + -- better to use tidyOpenType here pprTyCon :: PrintExplicitForalls -> ShowSub -> TyCon -> SDoc pprTyCon pefas ss tyCon |