Commit ac4f5522 authored by CJ East's avatar CJ East

Fix to permit use of future IHaskellDisplay instance.

See comments at https://github.com/gibiansky/IHaskell/pull/330
parent 40cb20de
......@@ -699,27 +699,35 @@ evalCommand output (Expression expr) state = do
-- typeclass instance, this will throw an exception and thus `attempt` will
-- return False, and we just resort to plaintext.
let displayExpr = printf "(IHaskell.Display.display (%s))" expr :: String
write displayExpr
canRunDisplay <- attempt $ exprType displayExpr
-- Check if this is a widget.
let widgetExpr = printf "(IHaskell.Display.Widget (%s))" expr :: String
isWidget <- attempt $ exprType widgetExpr
-- Check if this is a declaration
-- let declExpr = printf "((id :: Q [Dec] -> Q [Dec]) (%s))" expr::String
-- Check if this is a template haskell declaration
let declExpr = printf "((id :: DecsQ -> DecsQ) (%s))" expr::String
isDeclaration <- attempt $ exprType declExpr
isTHDeclaration <- attempt $ exprType declExpr
write $ "Can Display: " ++ show canRunDisplay
write $ " Is Widget: " ++ show isWidget
if isDeclaration
then do
write $ " Is Declaration: " ++ show isDeclaration
(GHC.runDecls expr) >> return ()
else
write $ " Is Declaration:" ++ show isDeclaration
write $ "Is Widget: " ++ show isWidget
write $ "Is Declaration: " ++ show isTHDeclaration
if isTHDeclaration
-- If it typechecks as a DecsQ, we do not want to display the DecsQ,
-- we just want the declaration made.
then do
write $ "Suppressing display for template haskell declaration"
GHC.runDecls expr
return EvalOut {
evalStatus = Success,
evalResult = mempty,
evalState = state,
evalPager = "",
evalComms = []
}
else do
if canRunDisplay
then do
-- Use the display. As a result, `it` is set to the output.
......@@ -729,18 +737,6 @@ evalCommand output (Expression expr) state = do
if isWidget
then registerWidget out
else return out
else do
if isDeclaration
-- We do not want to display the DecsQ, we just want the
-- declaration made.
then do write $ "Suppressing display for template haskell declaration"
return EvalOut {
evalStatus = Success,
evalResult = mempty,
evalState = state,
evalPager = "",
evalComms = []
}
else do
-- Evaluate this expression as though it's just a statement.
-- The output is bound to 'it', so we can then use it.
......
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