Commit 3d38d41f authored by Adam Vogt's avatar Adam Vogt

add Monoid Display instance

parent 9e746d84
...@@ -351,7 +351,7 @@ evalCommand _ (Import importStr) state = wrapExecution state $ do ...@@ -351,7 +351,7 @@ evalCommand _ (Import importStr) state = wrapExecution state $ do
return $ if "Test.Hspec" `isInfixOf` importStr return $ if "Test.Hspec" `isInfixOf` importStr
then displayError $ "Warning: Hspec is unusable in IHaskell until the resolution of GHC bug #8639." ++ then displayError $ "Warning: Hspec is unusable in IHaskell until the resolution of GHC bug #8639." ++
"\nThe variable `it` is shadowed and cannot be accessed, even in qualified form." "\nThe variable `it` is shadowed and cannot be accessed, even in qualified form."
else Display [] else mempty
where where
implicitImportOf :: ImportDecl RdrName -> InteractiveImport -> Bool implicitImportOf :: ImportDecl RdrName -> InteractiveImport -> Bool
implicitImportOf _ (IIModule _) = False implicitImportOf _ (IIModule _) = False
...@@ -423,7 +423,7 @@ evalCommand _ (Directive SetDynFlag flags) state = wrapExecution state $ do ...@@ -423,7 +423,7 @@ evalCommand _ (Directive SetDynFlag flags) state = wrapExecution state $ do
write $ "DynFlag: " ++ flags write $ "DynFlag: " ++ flags
errs <- setDynFlags (words flags) errs <- setDynFlags (words flags)
return $ case errs of return $ case errs of
[] -> [] [] -> mempty
_ -> displayError $ intercalate "\n" errs _ -> displayError $ intercalate "\n" errs
evalCommand a (Directive SetExtension opts) state = do evalCommand a (Directive SetExtension opts) state = do
...@@ -439,7 +439,7 @@ evalCommand a (Directive SetOption opts) state = do ...@@ -439,7 +439,7 @@ evalCommand a (Directive SetOption opts) state = do
ds -> error ("kernelOpts has duplicate:" ++ show (map getOptionName ds)) ds -> error ("kernelOpts has duplicate:" ++ show (map getOptionName ds))
| w <- words opts ] | w <- words opts ]
warn warn
| null lost = [] | null lost = mempty
| otherwise = displayError ("Could not recognize options: " ++ intercalate "," lost) | otherwise = displayError ("Could not recognize options: " ++ intercalate "," lost)
return EvalOut { return EvalOut {
evalStatus = if null lost then Success else Failure, evalStatus = if null lost then Success else Failure,
...@@ -482,7 +482,7 @@ evalCommand publish (Directive ShellCmd ('!':cmd)) state = wrapExecution state $ ...@@ -482,7 +482,7 @@ evalCommand publish (Directive ShellCmd ('!':cmd)) state = wrapExecution state $
if exists if exists
then do then do
setCurrentDirectory directory setCurrentDirectory directory
return $ Display [] return $ mempty
else else
return $ displayError $ printf "No such directory: '%s'" directory return $ displayError $ printf "No such directory: '%s'" directory
cmd -> do cmd -> do
...@@ -616,7 +616,7 @@ evalCommand _ (Directive GetInfo str) state = safely state $ do ...@@ -616,7 +616,7 @@ evalCommand _ (Directive GetInfo str) state = safely state $ do
return EvalOut { return EvalOut {
evalStatus = Success, evalStatus = Success,
evalResult = Display [], evalResult = mempty,
evalState = state, evalState = state,
evalPager = output evalPager = output
} }
...@@ -786,7 +786,7 @@ evalCommand _ (Declaration decl) state = wrapExecution state $ do ...@@ -786,7 +786,7 @@ evalCommand _ (Declaration decl) state = wrapExecution state $ do
-- Display the types of all bound names if the option is on. -- Display the types of all bound names if the option is on.
-- This is similar to GHCi :set +t. -- This is similar to GHCi :set +t.
if not $ useShowTypes state if not $ useShowTypes state
then return $ Display [] then return mempty
else do else do
-- Get all the type strings. -- Get all the type strings.
types <- forM nonDataNames $ \name -> do types <- forM nonDataNames $ \name -> do
...@@ -815,7 +815,7 @@ evalCommand _ (ParseError loc err) state = do ...@@ -815,7 +815,7 @@ evalCommand _ (ParseError loc err) state = do
hoogleResults :: KernelState -> [Hoogle.HoogleResult] -> EvalOut hoogleResults :: KernelState -> [Hoogle.HoogleResult] -> EvalOut
hoogleResults state results = EvalOut { hoogleResults state results = EvalOut {
evalStatus = Success, evalStatus = Success,
evalResult = Display [], evalResult = mempty,
evalState = state, evalState = state,
evalPager = output evalPager = output
} }
...@@ -877,7 +877,7 @@ doLoadModule name modName = flip gcatch unload $ do ...@@ -877,7 +877,7 @@ doLoadModule name modName = flip gcatch unload $ do
setSessionDynFlags flags{ hscTarget = HscInterpreted } setSessionDynFlags flags{ hscTarget = HscInterpreted }
case result of case result of
Succeeded -> return $ Display [] Succeeded -> return mempty
Failed -> return $ displayError $ "Failed to load module " ++ modName Failed -> return $ displayError $ "Failed to load module " ++ modName
where where
unload :: SomeException -> Ghc Display unload :: SomeException -> Ghc Display
......
...@@ -72,6 +72,13 @@ data Display = Display [DisplayData] ...@@ -72,6 +72,13 @@ data Display = Display [DisplayData]
deriving (Show, Typeable, Generic) deriving (Show, Typeable, Generic)
instance Serialize Display instance Serialize Display
instance Monoid Display where
mempty = Display []
ManyDisplay a `mappend` ManyDisplay b = ManyDisplay (a ++ b)
ManyDisplay a `mappend` b = ManyDisplay (a ++ [b])
a `mappend` ManyDisplay b = ManyDisplay (a : b)
a `mappend` b = ManyDisplay [a,b]
-- | All state stored in the kernel between executions. -- | All state stored in the kernel between executions.
data KernelState = KernelState data KernelState = KernelState
{ getExecutionCounter :: Int, { getExecutionCounter :: Int,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment