diff --git a/notebooks/Test.ipynb b/notebooks/Test.ipynb index 58011f4e..79d172a6 100644 --- a/notebooks/Test.ipynb +++ b/notebooks/Test.ipynb @@ -36,8 +36,8 @@ "cell_type": "code", "collapsed": false, "input": [ - ":load a/Test.hs\n", - "test" + ":ext Impli\n", + "4 + 4" ], "language": "python", "metadata": { @@ -48,11 +48,11 @@ "metadata": {}, "output_type": "display_data", "text": [ - "3" + "8" ] } ], - "prompt_number": 14 + "prompt_number": 2 }, { "cell_type": "code", diff --git a/src/IHaskell/Eval/Evaluate.hs b/src/IHaskell/Eval/Evaluate.hs index ba5b5838..8153c7b7 100644 --- a/src/IHaskell/Eval/Evaluate.hs +++ b/src/IHaskell/Eval/Evaluate.hs @@ -105,6 +105,7 @@ instance MonadIO.MonadIO Interpreter where globalImports :: [String] globalImports = [ "import IHaskell.Display()" + , "import qualified Prelude as IHaskellPrelude" , "import qualified IHaskell.Display" , "import qualified IHaskell.IPython.Stdin" , "import qualified System.Posix.IO as IHaskellIO" @@ -409,6 +410,19 @@ evalCommand output (Directive SetDynFlag flags) state = let display = case errs of [] -> mempty _ -> displayError $ intercalate "\n" errs + + -- For -XNoImplicitPrelude, remove the Prelude import. + -- For -XImplicitPrelude, add it back in. + case flag of + "-XNoImplicitPrelude" -> + evalImport "import qualified Prelude as Prelude" + "-XImplicitPrelude" -> do + importDecl <- parseImportDecl "import Prelude" + let implicitPrelude = importDecl { ideclImplicit = True } + imports <- getContext + setContext $ IIDecl implicitPrelude : imports + _ -> return () + return EvalOut { evalStatus = Success, evalResult = display, @@ -1005,7 +1019,7 @@ capturedStatement output stmt = do -- Variable used to store true `it` value. itVariable = var "it_var_" - voidpf str = printf $ str ++ " >> return ()" + voidpf str = printf $ str ++ " IHaskellPrelude.>> IHaskellPrelude.return ()" -- Statements run before the thing we're evaluating. initStmts =