@@ -354,29 +354,39 @@ handleTypeOf value = do
354 Just (ty, _, _) -> PSCI . outputStrLn . P.prettyPrintType $ ty
354 Just (ty, _, _) -> PSCI . outputStrLn . P.prettyPrintType $ ty
355 Nothing -> PSCI $ outputStrLn "Could not find type"
355 Nothing -> PSCI $ outputStrLn "Could not find type"
358+-- Pretty print a module's signatures
360+printModuleSignatures :: P.ModuleName -> P.Environment -> PSCI ()
361+printModuleSignatures moduleName env =
362+ PSCI $ let namesEnv = P.names env
363+ moduleNamesIdent = (filter ((== moduleName) . fst) . M.keys) namesEnv
364+ in case moduleNamesIdent of
365+ [] -> outputStrLn $ "This module '"++ P.runModuleName moduleName ++"' does not export functions."
369+ . map (showType . findType namesEnv)) moduleNamesIdent
370+ where findType :: M.Map (P.ModuleName, P.Ident) (P.Type, P.NameKind, P.NameVisibility) -> (P.ModuleName, P.Ident) -> (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility))
371+ findType envNames m@(_, mIdent) = (mIdent, M.lookup m envNames)
372+ showType :: (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility)) -> String
373+ showType (mIdent, Just (mType, _, _)) = show mIdent ++ " :: " ++ P.prettyPrintType mType
374+ showType _ = error "The impossible happened in printModuleSignatures."
358-- Browse a module and displays its signature (if module exists).
377-- Browse a module and displays its signature (if module exists).
360handleBrowse :: P.ModuleName -> PSCI ()
379handleBrowse :: P.ModuleName -> PSCI ()
361handleBrowse moduleName = do
380handleBrowse moduleName = do
362 st <- PSCI $ lift get
381 st <- PSCI $ lift get
382+ let loadedModules = psciLoadedModules st
363− e <- psciIO . runMake $ P.make modulesDir options (psciLoadedModules st) []
383+ env <- psciIO . runMake $ P.make modulesDir options loadedModules []
364− PSCI $ case e of
384+ case env of
365− Left err -> outputStrLn err
385+ Left err -> PSCI $ outputStrLn err
366− Right env' ->
386+ Right env' ->
367− let namesEnv = P.names env'
387+ if moduleName `notElem` (nub . map ((\ (P.Module modName _ _ ) -> modName) . snd)) loadedModules
368− moduleNamesIdent = (filter ((== moduleName) . fst) . M.keys) namesEnv
369− in case moduleNamesIdent of
370− [] -> outputStrLn $ "Either you entered an invalid module name (see `:s loaded`) or the module '"++ P.runModuleName moduleName ++"' does not export functions."
388+ then PSCI $ outputStrLn $ "Module '" ++ N.runModuleName moduleName ++ "' is not valid."
371− _ -> ( outputStrLn
389+ else printModuleSignatures moduleName env'
374− . map (showType . findType namesEnv)) moduleNamesIdent
375− where findType :: M.Map (P.ModuleName, P.Ident) (P.Type, P.NameKind, P.NameVisibility) -> (P.ModuleName, P.Ident) -> (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility))
376− findType envNames m@(_, mIdent) = (mIdent, M.lookup m envNames)
377− showType :: (P.Ident, Maybe (P.Type, P.NameKind, P.NameVisibility)) -> String
378− showType (mIdent, Just (mType, _, _)) = show mIdent ++ " :: " ++ P.prettyPrintType mType
379− showType _ = error "The impossible happened in handleBrowse."
382-- Takes a value and prints its kind
392-- Takes a value and prints its kind