From 4899a56bd4455b9b1b285f1573f0a2376bc4f043 Mon Sep 17 00:00:00 2001 From: "claus.reinke@talk21.com" Date: Thu, 8 Nov 2007 01:31:47 +0000 Subject: [PATCH] FIX #1847 (improve :browse! docs, fix unqual) - add example to docs, explain how to interpret output of `:browse! Data.Maybe` - print unqualified names according to current context, not the context of the target module --- compiler/ghci/InteractiveUI.hs | 12 ++++++++---- docs/users_guide/ghci.xml | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/compiler/ghci/InteractiveUI.hs b/compiler/ghci/InteractiveUI.hs index f792acc..e5c6813 100644 --- a/compiler/ghci/InteractiveUI.hs +++ b/compiler/ghci/InteractiveUI.hs @@ -167,8 +167,8 @@ helpText = " evaluate/run \n" ++ " :{\\n ..lines.. \\n:}\\n multiline command\n" ++ " :add ... add module(s) to the current target set\n" ++ - " :browse[!] [-s] [[*]] display the names defined by module \n" ++ - " (!: more details; -s: sort; *: all top-level names)\n" ++ + " :browse[!] [[*]] display the names defined by module \n" ++ + " (!: more details; *: all top-level names)\n" ++ " :cd change directory to \n" ++ " :cmd run the commands returned by ::IO String\n" ++ " :ctags [] create tags file for Vi (default: \"tags\")\n" ++ @@ -1171,15 +1171,19 @@ browseCmd bang m = browseModule :: Bool -> Module -> Bool -> GHCi () browseModule bang modl exports_only = do s <- getSession + -- :browse! reports qualifiers wrt current context + current_unqual <- io (GHC.getPrintUnqual s) -- Temporarily set the context to the module we're interested in, -- just so we can get an appropriate PrintUnqualified (as,bs) <- io (GHC.getContext s) prel_mod <- getPrelude io (if exports_only then GHC.setContext s [] [prel_mod,modl] else GHC.setContext s [modl] []) - unqual <- io (GHC.getPrintUnqual s) + target_unqual <- io (GHC.getPrintUnqual s) io (GHC.setContext s as bs) + let unqual = if bang then current_unqual else target_unqual + mb_mod_info <- io $ GHC.getModuleInfo s modl case mb_mod_info of Nothing -> throwDyn (CmdLineError ("unknown module: " ++ @@ -1220,7 +1224,7 @@ browseModule bang modl exports_only = do labels [] = text "-- not currently imported" labels l = text $ intercalate "\n" $ map qualifier l qualifier = maybe "-- defined locally" - (("-- imported from "++) . intercalate ", " + (("-- imported via "++) . intercalate ", " . map GHC.moduleNameString) importInfo = RdrName.getGRE_NameQualifier_maybes rdr_env modNames = map (importInfo . GHC.getName) things diff --git a/docs/users_guide/ghci.xml b/docs/users_guide/ghci.xml index bac55ed..69fcc36 100644 --- a/docs/users_guide/ghci.xml +++ b/docs/users_guide/ghci.xml @@ -1740,6 +1740,32 @@ $ ghci -lm The !-form also annotates the listing with comments giving possible imports for each group of entries. + +Prelude> :browse! Data.Maybe +-- not currently imported +Data.Maybe.catMaybes :: [Maybe a] -> [a] +Data.Maybe.fromJust :: Maybe a -> a +Data.Maybe.fromMaybe :: a -> Maybe a -> a +Data.Maybe.isJust :: Maybe a -> Bool +Data.Maybe.isNothing :: Maybe a -> Bool +Data.Maybe.listToMaybe :: [a] -> Maybe a +Data.Maybe.mapMaybe :: (a -> Maybe b) -> [a] -> [b] +Data.Maybe.maybeToList :: Maybe a -> [a] +-- imported via Prelude +Just :: a -> Maybe a +data Maybe a = Nothing | Just a +Nothing :: Maybe a +maybe :: b -> (a -> b) -> Maybe a -> b + + + This output shows that, in the context of the current session, in the scope + of Prelude, the first group of items from + Data.Maybe have not been imported (but are available in + fully qualified form in the GHCi session - see ), whereas the second group of items have been + imported via Prelude and are therefore available either + unqualified, or with a Prelude. qualifier. + -- 1.7.10.4