Commit 77701bfa authored by Andrew Gibiansky's avatar Andrew Gibiansky

qualified IHaskell implementation imports, closes #146

parent a3222f61
......@@ -368,13 +368,13 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
"prompt_number": 12
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we were playing around with designing GUI applications for color-blind users, we might want to actually *see* these colors, instead of just seeing the text \"Red\", \"Green\", and \"Blue\" when we are debugging.\n",
"If we were playing around with designing GUI applications, for instance, we might want to actually *see* these colors, instead of just seeing the text \"Red\", \"Green\", and \"Blue\" when we are debugging.\n",
"\n",
"IHaskell lets you define a custom display mechanism for any data type via its `IHaskellDisplay` typeclass. Since you can use IHaskell in console mode as well as notebook mode, you can provide a list of display outputs for any data type, and the frontend will simply choose the best one. Here's how you would implement a very simple display mechanism for this `Color` data type:"
]
......@@ -398,7 +398,7 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
"prompt_number": 13
},
{
"cell_type": "markdown",
......@@ -440,7 +440,7 @@
"output_type": "display_data"
}
],
"prompt_number": 6
"prompt_number": 14
},
{
"cell_type": "markdown",
......@@ -507,7 +507,7 @@
]
}
],
"prompt_number": 7
"prompt_number": 15
},
{
"cell_type": "markdown",
......@@ -573,7 +573,7 @@
]
}
],
"prompt_number": 8
"prompt_number": 16
},
{
"cell_type": "markdown",
......@@ -1072,7 +1072,7 @@
"</div> </div> <div class=\"suggestion-row\" style=\"float: left;\"> <div class=\"suggestion-warning\">Why Not:</div> <div class=\"highlight-code\" id=\"haskell\"> f 3\n",
"</div> </div> <div class=\"suggestion-name\" style=\"clear:both;\"> Use print</div> <div class=\"suggestion-row\" style=\"float: left;\"> <div class=\"suggestion-error\">Found:</div> <div class=\"highlight-code\" id=\"haskell\"> putStrLn (show 3)\n",
"</div> </div> <div class=\"suggestion-row\" style=\"float: left;\"> <div class=\"suggestion-error\">Why Not:</div> <div class=\"highlight-code\" id=\"haskell\"> print 3\n",
"</div> </div> <div class=\"suggestion-name\" style=\"clear:both;\"> Redundant do</div> <div class=\"suggestion-row\" style=\"float: left;\"> <div class=\"suggestion-error\">Found:</div> <div class=\"highlight-code\" id=\"haskell\">return 3\n",
"</div> </div> <div class=\"suggestion-name\" style=\"clear:both;\"> Redundant do</div> <div class=\"suggestion-row\" style=\"float: left;\"> <div class=\"suggestion-error\">Found:</div> <div class=\"highlight-code\" id=\"haskell\"> do return 3\n",
"</div> </div> <div class=\"suggestion-row\" style=\"float: left;\"> <div class=\"suggestion-error\">Why Not:</div> <div class=\"highlight-code\" id=\"haskell\"> return 3\n",
"</div> </div> "
],
......@@ -1093,7 +1093,7 @@
" print 3\n",
"Line 11: Redundant do\n",
"Found:\n",
"return 3\n",
" do return 3\n",
"\n",
"Why not:\n",
" return 3"
......
......@@ -98,13 +98,10 @@ instance MonadIO.MonadIO Interpreter where
globalImports :: [String]
globalImports =
[ "import IHaskell.Display"
[ "import IHaskell.Display()"
, "import qualified IPython.Stdin"
, "import Control.Applicative ((<$>))"
, "import GHC.IO.Handle (hDuplicateTo, hDuplicate, hClose)"
, "import System.Posix.IO"
, "import System.Posix.Files"
, "import System.IO"
, "import qualified System.Posix.IO as IHaskellIO"
, "import qualified System.IO as IHaskellSysIO"
]
......@@ -954,19 +951,19 @@ capturedStatement output stmt = do
-- Statements run before the thing we're evaluating.
initStmts =
[ printf "let %s = it" itVariable
, printf "(%s, %s) <- createPipe" readVariable writeVariable
, printf "%s <- dup stdOutput" oldVariable
, voidpf "dupTo %s stdOutput" writeVariable
, voidpf "hSetBuffering stdout NoBuffering"
, printf "(%s, %s) <- IHaskellIO.createPipe" readVariable writeVariable
, printf "%s <- IHaskellIO.dup IHaskellIO.stdOutput" oldVariable
, voidpf "IHaskellIO.dupTo %s IHaskellIO.stdOutput" writeVariable
, voidpf "IHaskellSysIO.hSetBuffering IHaskellSysIO.stdout IHaskellSysIO.NoBuffering"
, printf "let it = %s" itVariable
]
-- Statements run after evaluation.
postStmts =
[ printf "let %s = it" itVariable
, voidpf "hFlush stdout"
, voidpf "dupTo %s stdOutput" oldVariable
, voidpf "closeFd %s" writeVariable
, voidpf "IHaskellSysIO.hFlush IHaskellSysIO.stdout"
, voidpf "IHaskellIO.dupTo %s IHaskellIO.stdOutput" oldVariable
, voidpf "IHaskellIO.closeFd %s" writeVariable
, printf "let it = %s" itVariable
]
pipeExpr = printf "let %s = %s" (var "pipe_var_") readVariable
......
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