summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorRichard Eisenberg <eir@cis.upenn.edu>2016-04-22 22:39:17 -0400
committerRichard Eisenberg <eir@cis.upenn.edu>2016-06-23 15:17:43 -0400
commit8035d1a5dc7290e8d3d61446ee4861e0b460214e (patch)
tree2e517feff25329abb942184ac4a7d20c9f77ba29 /ghc
parent9a34bf1985035858ece043bf38b47b6ff4b88efb (diff)
downloadhaskell-8035d1a5dc7290e8d3d61446ee4861e0b460214e.tar.gz
Fix #10963 and #11975 by adding new cmds to GHCi.
See the user's guide entry or the Note [TcRnExprMode] in TcRnDriver. Test cases: ghci/scripts/T{10963,11975}
Diffstat (limited to 'ghc')
-rw-r--r--ghc/GHCi/UI.hs12
-rw-r--r--ghc/GHCi/UI/Info.hs2
2 files changed, 10 insertions, 4 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index c04bf2d194..1e27c7a861 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -299,6 +299,8 @@ defFullHelpText =
" :run function [<arguments> ...] run the function with the given arguments\n" ++
" :script <file> run the script <file>\n" ++
" :type <expr> show the type of <expr>\n" ++
+ " :type +d <expr> show the type of <expr>, defaulting type variables\n" ++
+ " :type +v <expr> show the type of <expr>, with its specified tyvars\n" ++
" :undef <cmd> undefine user-defined command :<cmd>\n" ++
" :!<command> run the shell command <command>\n" ++
"\n" ++
@@ -1811,12 +1813,16 @@ exceptT :: Applicative m => Either e a -> ExceptT e m a
exceptT = ExceptT . pure
-----------------------------------------------------------------------------
--- | @:type@ command
+-- | @:type@ command. See also Note [TcRnExprMode] in TcRnDriver.
typeOfExpr :: String -> InputT GHCi ()
typeOfExpr str = handleSourceError GHC.printException $ do
- ty <- GHC.exprType str
- printForUser $ sep [text str, nest 2 (dcolon <+> pprTypeForUser ty)]
+ let (mode, expr_str) = case break isSpace str of
+ ("+d", rest) -> (GHC.TM_Default, dropWhile isSpace rest)
+ ("+v", rest) -> (GHC.TM_NoInst, dropWhile isSpace rest)
+ _ -> (GHC.TM_Inst, str)
+ ty <- GHC.exprType mode expr_str
+ printForUser $ sep [text expr_str, nest 2 (dcolon <+> pprTypeForUser ty)]
-----------------------------------------------------------------------------
-- | @:type-at@ command
diff --git a/ghc/GHCi/UI/Info.hs b/ghc/GHCi/UI/Info.hs
index 2c44e3f8e2..ef5e9ef207 100644
--- a/ghc/GHCi/UI/Info.hs
+++ b/ghc/GHCi/UI/Info.hs
@@ -215,7 +215,7 @@ findType infos span0 string = do
MaybeT $ pure $ M.lookup name infos
case resolveType (modinfoSpans info) (spanInfoFromRealSrcSpan' span0) of
- Nothing -> (,) info <$> lift (exprType string)
+ Nothing -> (,) info <$> lift (exprType TM_Inst string)
Just ty -> return (info, ty)
where
-- | Try to resolve the type display from the given span.