Commit 318234ca authored by Andrew Gibiansky's avatar Andrew Gibiansky

Closes issue #21, also added some images

parent 4f92c0b3
This diff is collapsed.
...@@ -652,38 +652,29 @@ evalCommand output (Statement stmt) state = wrapExecution state $ do ...@@ -652,38 +652,29 @@ evalCommand output (Statement stmt) state = wrapExecution state $ do
evalCommand output (Expression expr) state = do evalCommand output (Expression expr) state = do
write $ "Expression:\n" ++ expr write $ "Expression:\n" ++ expr
-- Check if we can display this.
let displayExpr = printf "(IHaskell.Display.display (%s))" expr :: String
canRunDisplay <- attempt $ exprType displayExpr
-- Evaluate this expression as though it's just a statement.
-- The output is bound to 'it', so we can then use it.
evalOut <- evalCommand output (Statement expr) state
-- Try to use `display` to convert our type into the output -- Try to use `display` to convert our type into the output
-- DisplayData. If typechecking fails and there is no appropriate -- DisplayData. If typechecking fails and there is no appropriate
-- typeclass instance, this will throw an exception and thus `attempt` will -- typeclass instance, this will throw an exception and thus `attempt` will
-- return False, and we just resort to plaintext. -- return False, and we just resort to plaintext.
let out = evalResult evalOut let displayExpr = printf "(IHaskell.Display.display (%s))" expr :: String
showErr = isShowError out canRunDisplay <- attempt $ exprType displayExpr
write $ printf "%s: Attempting %s" (if canRunDisplay then "Success" else "Failure") displayExpr
write $ "Show Error: " ++ show showErr if canRunDisplay
write $ show out then useDisplay displayExpr
else do
-- If evaluation failed, return the failure. If it was successful, we -- Evaluate this expression as though it's just a statement.
-- may be able to use the IHaskellDisplay typeclass. -- The output is bound to 'it', so we can then use it.
if not canRunDisplay evalOut <- evalCommand output (Statement expr) state
then return $ if not showErr || useShowErrors state
then evalOut let out = evalResult evalOut
else postprocessShowError evalOut showErr = isShowError out
else case evalStatus evalOut of
Success -> useDisplay displayExpr -- If evaluation failed, return the failure. If it was successful, we
-- may be able to use the IHaskellDisplay typeclass.
-- If something other than the show failed, don't use display, just return $ if not showErr || useShowErrors state
-- show the error message. then evalOut
Failure -> if showErr else postprocessShowError evalOut
then useDisplay displayExpr
else return evalOut
where where
-- Try to evaluate an action. Return True if it succeeds and False if -- Try to evaluate an action. Return True if it succeeds and False if
......
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