IHaskell/notebooks/IHaskell.ipynb

3319 lines
251 KiB
Plaintext
Raw Normal View History

2014-01-30 16:30:21 -08:00
{
"cells": [
2014-01-30 16:30:21 -08:00
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"![](https://raw.githubusercontent.com/gibiansky/IHaskell/master/images/ihaskell-logo-small.png)\n",
"\n",
"IHaskell Notebook\n",
"===\n",
"Hello, and welcome to the **IHaskell Notebook**. IHaskell Notebook is similar to an interactive shell along the lines of GHCi. However, it is much more powerful, and provides features such as syntax highlighting, autocompletion, multi-line input cells, integrated documentation, rich output visualization, and more. In this notebook, I'd like to demonstrate many of the awesome features IHaskell provides.\n",
"\n",
"IHaskell is implemented as a language kernel for the [IPython](http://ipython.org) project, which means that although the entire thing is written only in Haskell, we get a beautiful notebook interface practically for free.\n",
"\n",
"We can start with very simple Haskell expressions:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"8"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
2014-01-30 16:30:21 -08:00
},
{
"data": {
"text/plain": [
"\"Hello, World!\""
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- First of all, we can evaluate simple expressions.\n",
"3 + 5\n",
"\"Hello, \" ++ \"World!\""
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"As you can see, each input cell get an execution number. The first input cell is labeled `In [1]`. Just like in GHCi, the output of the last executed statement or expression is available via the `it` variable - however, in addition, the output of the $n$th cell is available via the `itN` variable. For example, if we wanted to see what the first cell printed, we can go ahead and output that:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"\"Hello, World!\""
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"it1"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"In addition to simple code cells such as the ones you see, you can also have other types of cells. All of this inline text, for instance, is written using Markdown cells, which support the majority of Github markdown syntax. This lets you embed images and formatting and arbitrary HTML interspersed with your Haskell code. In addition, you can export these notebooks into HTML or even as presentations using `reveal.js`. \n",
"\n",
"Alright, back to code. Let's do something slightly fancier:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"\"Hello, World!\""
]
2014-06-11 21:02:30 -07:00
},
2014-06-11 21:27:17 -07:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- Unlike in GHCi, we can have multi-line expressions.\n",
"concat [\n",
" \"Hello\",\n",
" \", \",\n",
" \"World!\"\n",
" ] :: String"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"In addition to multi-line expressions, IHaskell supports most things that you could put in a standard Haskell file. For example, we can have function bindings without the `let` that GHCi requires. (As long as you group type signatures and their corresponding declarations together, you can use pattern matching and put signatures on your top-level declarations!)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"100"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
2014-01-30 16:30:21 -08:00
},
{
"data": {
"text/plain": [
"12"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"thing :: String -> Int -> Int\n",
"thing \"no\" _ = 100\n",
"thing str int = int + length str\n",
"\n",
"thing \"no\" 10\n",
"thing \"ah\" 10"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"So far we've just looked at pure functions, but nothing is stopping us from doing IO."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"\"What's going on?\""
]
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"print \"What's going on?\""
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"IHaskell supports most GHC extensions via the `:extension` directive (or any shorthand thereof)."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><span class='err-msg'>interactive:IHaskell172.Thing has no constructors (EmptyDataDecls permits this)<br/>In the data declaration for interactive:IHaskell172.Thing</span>"
],
"text/plain": [
"interactive:Ghci172.Thing has no constructors (EmptyDataDecls permits this)\n",
"In the data declaration for interactive:Ghci172.Thing"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- We can disable extensions.\n",
":ext NoEmptyDataDecls\n",
"data Thing"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"-- And enable extensions.\n",
":ext EmptyDataDecls\n",
"data Thing"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"Data declarations do pretty much what you expect, and work fine on multiple lines. If a declaration turns out to be not quite what you wanted, you can just go back, edit it, and re-evaluate the code cell."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[A \"Hello\",B 10]"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- Various data declarations work fine.\n",
"data One\n",
" = A String\n",
" | B Int\n",
" deriving Show\n",
"\n",
"print [A \"Hello\", B 10]"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"Although this doesn't hold everywhere, we've tried to keep IHaskell relatively similar to GHCi in terms of naming. So, just like in GHCi, you can inspect types with `:type` (or shorthands):"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><span class='get-type'>3 + 3 :: forall a. Num a => a</span>"
],
"text/plain": [
"3 + 3 :: forall a. Num a => a"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- We can look at types like in GHCi.\n",
":ty 3 + 3"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"The same goes for the `:info` command. However, unlike GHCi, which simply prints info, the IHaskell notebook brings up a separate pane."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- What is the Integral typeclass?\n",
":info Integral"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"If you're looking at this notebook after it's been exported to HTML, you won't be able to see this interactive pane that pops up after this is evaluated. However, you can disable the interactive pager, and instead just show the output below the cell:"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"-- Only takes effect on later cells, so stick it in its own cell.\n",
":opt no-pager"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><div style='background: rgb(247, 247, 247);'><form><textarea id='code'>class (Real a, Enum a) => Integral a where\n",
" quot :: a -> a -> a\n",
" rem :: a -> a -> a\n",
" div :: a -> a -> a\n",
" mod :: a -> a -> a\n",
" quotRem :: a -> a -> (a, a)\n",
" divMod :: a -> a -> (a, a)\n",
" toInteger :: a -> Integer\n",
" \t-- Defined in GHC.Real\n",
"instance Integral a => Integral (Tagged s a) -- Defined in Data.Tagged\n",
"instance Integral Integer -- Defined in GHC.Real\n",
"instance Integral Int -- Defined in GHC.Real</textarea></form></div><script>CodeMirror.fromTextArea(document.getElementById('code'), {mode: 'haskell', readOnly: 'nocursor'});</script>\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":info Integral"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"We can now write slightly more complicated scripts."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1\n",
"2\n",
"3\n",
"4\n",
"5"
]
2014-06-11 21:02:30 -07:00
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- Results are printed as we go, even from a single expression.\n",
"import Control.Monad\n",
"import Control.Concurrent\n",
"\n",
"forM_ [1..5] $ \\x -> do\n",
" print x\n",
" threadDelay $ 200 * 1000"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"This is where the similarities with GHCi end, and the particularly shiny features of IHaskell begin.\n",
"\n",
"Although looking at text outputs is often enough, there are many times where we really want a richer output. Suppose we have a custom data type for color:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"data Color = Red | Green | Blue"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"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:"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import IHaskell.Display\n",
"\n",
"instance IHaskellDisplay Color where\n",
" display color = return $ Display [html code]\n",
" where\n",
" code = concat [\"<div style='font-weight: bold; color:\"\n",
" , css color\n",
" , \"'>Look!</div>\"]\n",
" css Red = \"red\"\n",
" css Blue = \"blue\"\n",
" css Green = \"green\""
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"Once we define a custom `display :: a -> IO Display` function, we can simply output a `Color`:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><div style='font-weight: bold; color:red'>Look!</div>"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><div style='font-weight: bold; color:green'>Look!</div>"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><div style='font-weight: bold; color:blue'>Look!</div>"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Red\n",
"Green\n",
"Blue"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"The `DisplayData` type has several constructors which let you display your data as plain text, HTML, images (SVG, PNG, JPG), or even as LaTeX code.\n",
"\n",
"In order to ship an extension for IHaskell, simply create a package named `ihaskell-thing` with a module named `IHaskell.Display.Thing`. As long as `ihaskell-thing` is installed, IHaskell will detect and use it automatically.\n",
"\n",
"A number of packages already exist, which we can briefly look at. First, in `ihaskell-basic`, we have very simple displays for data types from `Prelude`."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><span style='color: green; font-weight: bold;'>Just</span><span style='font-family: monospace;'>()</span>"
],
"text/plain": [
"Just ()"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><span style='color: red; font-weight: bold;'>Nothing</span>"
],
"text/plain": [
"Nothing"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><div class='collapse-group'><span class='btn btn-default' href='#' id='unshowable'>Unshowable:<span class='show-type'>NoShow</span></span><span class='err-msg collapse'>No instance for (Show NoShow) arising from a use of print<br/>In a stmt of an interactive GHCi command: print it</span></div><script>$('#unshowable').on('click', function(e) {\n",
" e.preventDefault();\n",
" var $this = $(this);\n",
" var $collapse = $this.closest('.collapse-group').find('.err-msg');\n",
" $collapse.collapse('toggle');\n",
"});\n",
"</script>"
],
"text/plain": [
"No instance for (Show NoShow) arising from a use of print\n",
"In a stmt of an interactive GHCi command: print it"
]
2014-06-11 21:02:30 -07:00
},
2014-06-11 21:27:17 -07:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- We can display Maybes fancily for Show-able types.\n",
"Just ()\n",
"Nothing\n",
"\n",
"-- But it dies if it's not showable.\n",
"data NoShow = X Int\n",
"Just (X 3)"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"The `ihaskell-aeson` package adds a display for [Aeson](http://hackage.haskell.org/package/aeson) JSON `Value` types. These are automatically syntax highlighted and formatted nicely."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><div class=\"highlight-code\" id=\"javascript\">null</div>"
],
"text/plain": [
"null"
]
2014-06-11 21:02:30 -07:00
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><div class=\"highlight-code\" id=\"javascript\">true</div>"
],
"text/plain": [
"true"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><div class=\"highlight-code\" id=\"javascript\">{\n",
" \"x\": 3,\n",
" \"y\": 2\n",
"}</div>"
],
"text/plain": [
"{\n",
" \"x\": 3,\n",
" \"y\": 2\n",
"}"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- Aeson JSON data types are displayed nicely.\n",
":ext OverloadedStrings\n",
"\n",
"import Data.Aeson\n",
"\n",
"data Coord = Coord { x :: Double, y :: Double }\n",
"instance ToJSON Coord where\n",
" toJSON (Coord x y) = object [\"x\" .= x, \"y\" .= y]\n",
"\n",
"Null\n",
"Bool True\n",
"toJSON (Coord 3 2)"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"This syntax highlighting may not show up in the exported HTML, as it is done on the fly with Javascript. The result looks like this in the notebook:\n",
"\n",
"![](https://raw.githubusercontent.com/gibiansky/IHaskell/master/demo/json-demo.png)"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"The `ihaskell-blaze` package lets you play around with HTML straight from within IHaskell using the [Blaze](http://jaspervdj.be/blaze/tutorial.html) library."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><div style=\"color: red\">\n",
" <p>\n",
" This is an example of BlazeMarkup syntax.\n",
" </p>\n",
" <b>\n",
" Hello\n",
" </b>\n",
"</div>\n"
],
"text/plain": [
"<div style=\"color: red\">\n",
" <p>\n",
" This is an example of BlazeMarkup syntax.\n",
" </p>\n",
" <b>\n",
" Hello\n",
" </b>\n",
"</div>"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><img src=\"https://www.google.com/images/srpr/logo11w.png\" width=\"70\">\n",
"<img src=\"https://www.google.com/images/srpr/logo11w.png\" width=\"140\">\n",
"<img src=\"https://www.google.com/images/srpr/logo11w.png\" width=\"210\">\n",
"<img src=\"https://www.google.com/images/srpr/logo11w.png\" width=\"280\">\n",
"<img src=\"https://www.google.com/images/srpr/logo11w.png\" width=\"350\">\n"
],
"text/plain": [
"<img src=\"https://www.google.com/images/srpr/logo11w.png\" width=\"70\">\n",
"<img src=\"https://www.google.com/images/srpr/logo11w.png\" width=\"140\">\n",
"<img src=\"https://www.google.com/images/srpr/logo11w.png\" width=\"210\">\n",
"<img src=\"https://www.google.com/images/srpr/logo11w.png\" width=\"280\">\n",
"<img src=\"https://www.google.com/images/srpr/logo11w.png\" width=\"350\">"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- Small bits of HTML generated via Blaze are displayed.\n",
"\n",
"import Prelude hiding (div, id)\n",
"import Text.Blaze.Html4.Strict hiding (map, style)\n",
"import Text.Blaze.Html4.Strict.Attributes\n",
"\n",
"div ! style \"color: red\" $ do\n",
" p \"This is an example of BlazeMarkup syntax.\"\n",
" b \"Hello\"\n",
" \n",
"forM [1..5] $ \\size -> do\n",
" let s = toValue $ size * 70\n",
" img ! src \"https://www.google.com/images/srpr/logo11w.png\" ! width s"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"The `ihaskell-diagrams` package allows you to experiment with the [diagrams](http://projects.haskell.org/diagrams/) package. It requires the Cairo backend."
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": [
"iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAIAAAD2HxkiAAAABmJLR0QA/wD/AP+gvaeTAAAU60lEQVR4nO3dW2wUZR8G8Jk9tEVAgSCGRqPiIYRwwUUTDQmJd3qvXngFiey6u0UOJRUUohRMthwKSAkiAYmyyrFRCm1NiVIokkJL0lpKKKVQtLBIWexuD8vM7s58F8tXaw/b3Zn3nXfe2ed39fkBT/6++vhuO7v/inPnzl20aJEAACzU19c7Fi1atG/fPtaTAGQpt9ttYz0DQLZDCQEYQwkBGEMJARhDCQEYQwkBGEMJARhDCQEYQwkBGEMJARhDCQEYQwkBGEMJARhDCQEYQwkBGEMJARhDCQEYQwkBGEMJARhDCQEYQwkBGEMJARhDCQEYQwkBGEMJARhDCQEYQwkBGEMJARhDCQEYQwkBGEMJARhDCQEYQwkBGEMJARhDCQEYQwkBGEMJARhDCQEYQwkBGEMJARhDCQEYQwkBGEMJ+aaqqqqqrKcAXVBCvh06dCgQCLCeAnRxsB4AtBscHCwuLhYE4d13333qqadYjwMa4SbkmN/vD4fD4XC4tLSU9SygHUrIq46OjtLSUkmSJEny+/03b95kPRFohBLyatWqVTbbk398Nptt1apVbOcBzVBCLtXW1v7yyy+yLCf/Upblmpqa2tpatlOBNighf+LxuM/nG/FkQlVVn88Xj8dZTQWaoYT8+eabb7q7uxVFGf5/KorS3d29b98+VlOBZighZ0Kh0Nq1ayVJGv1LkiStXbs2FAoZP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-- We can draw diagrams, right in the notebook.\n",
":extension NoMonomorphismRestriction\n",
"import Diagrams.Prelude\n",
"\n",
"-- By Brent Yorgey\n",
"-- Draw a Sierpinski triangle!\n",
"sierpinski 1 = eqTriangle 1\n",
"sierpinski n = s\n",
" ===\n",
" (s ||| s) # centerX\n",
" where s = sierpinski (n-1)\n",
"\n",
"-- The `diagram` function is used to display them in the notebook.\n",
"diagram $ sierpinski 4\n",
" # centerXY\n",
" # fc black\n",
" `atop` square 10\n",
" # fc white"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"Just like with Diagrams, `ihaskell-charts` allows you to use the [Chart](https://github.com/timbod7/haskell-chart/wiki) library for plotting from within IHaskell. (You will need to install `cairo` as well, which may be a bit of a hassle.)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": [
"iVBORw0KGgoAAAANSUhEUgAAAcIAAAEsCAIAAADfNCTgAAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVR4nO3deVwU9f8H8NeyyyGg6CooivKTwyNSzLJUMLxQUVHDAxME0RTvAzUjNbW8K0tDLSVTv3lh5hHeiuaJeJUBWoIcCggoisACC+z8/pgigl1YmN2dneX9fPSH7nzmM+81fDnHZz4fEcMwIIQQUldGfBdACCHCRjFKCCGcUIwSQggnFKOEEMIJxSghhHAi4bsAohX+/v5//vln+W+NjY2dnJxGjRo1bNiwGvft3r17WVnZiRMnrK2tVbXJyMiQyWQtWrSwsLAA4OzszDDMpUuXWrZsqdnKbWxsevbsOWfOHEtLS449q8Lv9yWGgCGG6I033lD6v3vHjh017iuRSACkpaVV06Z///4AIiIi2N+ynaekpGipcjc3N4VCwb1zpfj9vsQA0EW9Ifvoo4+uX79+/fr1w4cPOzk5AVi3bp02DnTr1q1bt261aNFCUx3OnTv3+vXrUVFR06ZNA3D16tXLly9rqnPuNP59ibDxneNEK9hzum3btpV/sn37dgAmJibsad2LFy+mT5/evn17e3t7H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C0xMC43OTY4NzUgTCAzLjEwNTQ2OSAtMTAuNzk2ODc1IFogIi8+Cjwvc3
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- We can draw small charts in the notebook.\n",
"-- This example is taken from the haskell-chart documentation.\n",
"import Graphics.Rendering.Chart \n",
"import Data.Default.Class\n",
"import Control.Lens\n",
"\n",
"let values = [\n",
" (\"Mexico City\" , 19.2, 0),\n",
" (\"Mumbai\" , 12.9, 10), \n",
" (\"Sydney\" , 4.3, 0),\n",
" (\"London\" , 8.3, 0), \n",
" (\"New York\" , 8.2, 25)]\n",
" \n",
"pitem (s, v, o) = pitem_value .~ v\n",
" $ pitem_label .~ s\n",
" $ pitem_offset .~ o\n",
" $ def \n",
"\n",
"-- Convert to a renderable in order to display it.\n",
"toRenderable \n",
" $ pie_title .~ \"Relative Population\"\n",
" $ pie_plot . pie_data .~ map pitem values\n",
" $ def"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"By default, both `ihaskell-diagrams` and `ihaskell-chart` use SVG displays. However, the notebook does not support interactive resizing for SVG image. However, if you use `:set no-svg`, all SVG outputs will instead be shown as PNG images, and they can be resized easily."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": [
"iVBORw0KGgoAAAANSUhEUgAAAcIAAAEsCAIAAADfNCTgAAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVR4nO3deVwU9f8H8NeyyyGg6CooivKTwyNSzLJUMLxQUVHDAxME0RTvAzUjNbW8K0tDLSVTv3lh5hHeiuaJeJUBWoIcCggoisACC+z8/pgigl1YmN2dneX9fPSH7nzmM+81fDnHZz4fEcMwIIQQUldGfBdACCHCRjFKCCGcUIwSQggnFKOEEMIJxSghhHAi4bsAohX+/v5//vln+W+NjY2dnJxGjRo1bNiwGvft3r17WVnZiRMnrK2tVbXJyMiQyWQtWrSwsL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ESi6XW1lZ5eXlSSQ04ITwic5G9UhaWtq5c+dkMlmNLWmtCwBJSUmtW7emDCW8oxjVCwqFIjAw8Pvvv4+NjZ0yZUp4eHj17WmtC9CNUaI3KEb1QnJy8o0bNz7++OO5c+fu3r27RYsWAAICAu7duwcgNjY2KCio0loXSle2+Pzzzx0dHXv27BkbG1u1B/6+n1bQjVGiJyhG9YKDg0Pnzp1bt249derUkydPDhkyBICLi8uxY8cAHD161MXFpdJaF1VXtkhMTDxy5EhMTMy8efPGjRtXtQdev6Lm0dko0RMUo/oiIiIiMjKyRYsWs2fPHj9+PAAfH5/jx48DOH78+HvvvVdprQtUWdkiMjLS0dHx1KlTcrk8KyvrxYsXlXrg9ftpHg0aJXqCbs/rhWvXrhUXF/fp0+fNN99cvHixg4NDdna2s7NzUVH
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":opt no-svg\n",
"\n",
"toRenderable \n",
" $ pie_title .~ \"Relative Population\"\n",
" $ pie_plot . pie_data .~ map pitem values\n",
" $ def"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"Finally, the `ihaskell-magic` chart uses the [magic](http://hackage.haskell.org/package/magic) library (bindings to `libmagic`) to create a display mechanism for `ByteString`s. If you try to load an image, for instance, you will see that image immediately in the notebook."
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/png": [
"iVBORw0KGgoAAAANSUhEUgAAAfgAAAJRCAYAAACp06XEAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QwOFiME5jRT2QAAIABJREFUeNrs3XdUFFcfxvHv0pfeBEQRRFEsIAh2RTSKsZuEaDTFHrvR2E30jcYYFXvsGmuMxsRYY8USY1cEOzZQsRdgaUvb3fcPiliSgKKi+X3O2XN0mb07c2dmn7l3ylXodDr+RTWgNVAHKA8URwgh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qwo9hmBJnnLMabCwM3smhLA1RntqF6xIn5B3ZhyQEFFTxte6V35OhUHxnRlQfIHzJnYBLvs2dSzbcS4kCDuz/ycKadS8llYCmFfv0Ot2nV5f/Il4CTDg2pTu2ZLpkWmFnze/mnbEEK8NRS6gp8ILbp0GUyv8j1Tg7pzffILjqGTfJ1OpZZyYfogDn1qViizFxERgaenp2x1QgghCl1kZCQ+Pj6vpgX/mlKemCkLXvxZ9OZLWBYr/ZZCCCGkBS+kBS+EEEJa8EIIIYR4WSTghRBCCAl4IYQQQkjAC/GGU00zZlMlY6Ju/PeWXX38S0qb12RBjEY2BCEk4IUQWdK5MK0W5laNWHQt790caZyb4I+pTRMWX8v/XR5aVQQ/9m1EefusUe1sXKoQ1O0HTiQ+cY2sahNNzO1otyvxhZdA364awR83p5yZQlanEBLwQogsRpTvMYeBpQ4wauRWHmQ/ezczZjWDJkZSZfRMPnbN54OBNbf5tVNj+m6ypsui3Rw5+hfrZvWlmjaKmy9xUCaj0u0JmT+KQFv5mRBCAl4I8YipD4Nnd0f5+yA
]
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- This import is unnecessary, but ensures that\n",
"-- you actually have the magic library installed. Otherwise,\n",
"-- the bytestring will get displayed as a large string!\n",
"import IHaskell.Display.Magic\n",
"\n",
"import qualified Data.ByteString as B\n",
"B.readFile \"code/IHaskell/images/ihaskell-notebook.png\""
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"In addition to displaying outputs in a rich format, IHaskell has a bunch of useful features.\n",
"\n",
"For instance, the popular linting tool `hlint` is integrated and turned on by default. Let's write some ugly code, and see what it tells us:"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style> <div class=\"suggestion-name\" style=\"clear:both;\">Redundant $</div> <div class=\"suggestion-row\" style=\"float: left;\"> <div class=\"suggestion-warning\">Found:</div> <div class=\"highlight-code\" id=\"haskell\">f $ 3</div> </div> <div class=\"suggestion-row\" style=\"float: left;\"> <div class=\"suggestion-warning\">Why Not:</div> <div class=\"highlight-code\" id=\"haskell\">f 3</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)</div> </div> <div class=\"suggestion-row\" style=\"float: left;\"> <div class=\"suggestion-error\">Why Not:</div> <div class=\"highlight-code\" id=\"haskell\">print 3</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</div> </div> <div class=\"suggestion-row\" style=\"float: left;\"> <div class=\"suggestion-error\">Why Not:</div> <div class=\"highlight-code\" id=\"haskell\">return 3</div> </div> "
],
"text/plain": [
"Line 1: Redundant $\n",
"Found:\n",
"f $ 3\n",
"Why not:\n",
"f 3Line 1: Use print\n",
"Found:\n",
"putStrLn (show 3)\n",
"Why not:\n",
"print 3Line 1: Redundant do\n",
"Found:\n",
"do return 3\n",
"Why not:\n",
"return 3"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
2014-01-30 16:30:21 -08:00
},
{
"data": {
"text/plain": [
"4"
]
2014-06-11 21:02:30 -07:00
},
"metadata": {},
"output_type": "display_data"
2014-01-30 16:30:21 -08:00
},
{
"data": {
"text/plain": [
"3"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
2014-01-30 16:30:21 -08:00
},
{
"data": {
"text/plain": [
"3"
]
2014-06-11 21:02:30 -07:00
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- There is also hlint integration enabled by default.\n",
"-- If you write sketchy code, it will tell you:\n",
"f :: Int -> Int\n",
"f x = x + 1\n",
"\n",
"-- Most warnings are orange...\n",
"f $ 3\n",
"\n",
"-- But more severe warnings are red.\n",
"putStrLn (show 3)\n",
"do\n",
" return 3"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"If you're an experienced Haskeller, though, and don't want `hlint` telling you what to do, you can easily turn it off:"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"-- If hlint annoys you, though, you can turn it off.\n",
"-- Note that this only takes effect in the next cell execution.\n",
":opt no-lint"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- You could similarly use `:opt lint` to turn it back on.\n",
"f $ 3"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"In addition to `hlint` integration, IHaskell also integrates **Hoogle** for documentation searches. IHaskell provides two directives for searching Hoogle. The first of these, `:document` (or shorthands), looks for exact matches."
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html#v:filterM'>filterM</a> &#x2237; Monad m &#x21D2; (a &#x2192; m Bool) &#x2192; [a] &#x2192; m [a]</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>base</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Control.Monad</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>This generalizes the list-based filter function. \n",
"</div>\n",
"</div>\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":doc filterM"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"The other provided command is `:hoogle`. This does a normal Hoogle search, and thus lets you use imperfect matching and searching by type signature. This will show you documentation for things that match the desired type signature, as demonstrated below. It automatically formats inline Haskell code and hyperlinks the identifiers to their respective Haddock documentations."
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:zip'>zip</a> &#x2237; [a] &#x2192; [b] &#x2192; [(a, b)]</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>base</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Prelude</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>zip takes two lists and returns a list of corresponding pairs. If one input list is short, excess elements of the longer list are discarded. \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString-Builder-Prim.html#v:-62--42--60-'>(>*<)</a> &#x2237; Monoidal f &#x21D2; f a &#x2192; f b &#x2192; f (a, b)</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>bytestring</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.ByteString.Builder.Prim</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>A pairing/concatenation operator for builder primitives, both bounded and fixed size.\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>For example,\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-code'>> toLazyByteString (primFixed (char7 >*< char7) ('x','y')) = \"xy\"\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>We can combine multiple primitives using >*< multiple times.\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-code'>> toLazyByteString (primFixed (char7 >*< char7 >*< char7) ('x',('y','z'))) = \"xyz\" \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-Monad-Writer-Class.html#v:listens'>listens</a> &#x2237; MonadWriter w m &#x21D2; (w &#x2192; b) &#x2192; m a &#x2192; m (a, b)</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>mtl</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Control.Monad.Writer.Class</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>listens f m is an action that executes the action m and adds the result of applying f to the output to the value of the computation.\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>* f m = liftM (id *** f) (listen\n",
"</div>\n",
"<div class='hoogle-code'>> \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/mtl/latest/doc/html/Control-Monad-Writer-Class.html#v:listen'>listen</a> &#x2237; MonadWriter w m &#x21D2; m a &#x2192; m (a, w)</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>mtl</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Control.Monad.Writer.Class</span>)</span><div class='hoogle-doc'></div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/fgl/latest/doc/html/Data-Graph-Inductive-Graph.html#v:lpre'>lpre</a> &#x2237; Graph gr &#x21D2; gr a b &#x2192; Node &#x2192; [(Node, b)]</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>fgl</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Graph.Inductive.Graph</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>Find all Nodes that link to the given Node and the label of each link. \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/fgl/latest/doc/html/Data-Graph-Inductive-Graph.html#v:lsuc'>lsuc</a> &#x2237; Graph gr &#x21D2; gr a b &#x2192; Node &#x2192; [(Node, b)]</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>fgl</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Graph.Inductive.Graph</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>Find all Nodes that are linked from the given Node and the label of each link. \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/fgl/latest/doc/html/Data-Graph-Inductive-Query-Monad.html#v:apply'>apply</a> &#x2237; GT m g a &#x2192; m g &#x2192; m (a, g)</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>fgl</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Graph.Inductive.Query.Monad</span>)</span><div class='hoogle-doc'></div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/QuickCheck/latest/doc/html/Test-QuickCheck-Modifiers.html#v:shrinkState'>shrinkState</a> &#x2237; ShrinkState s a &#x21D2; a &#x2192; s &#x2192; [(a, s)]</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>QuickCheck</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Test.QuickCheck.Modifiers</span>)</span><div class='hoogle-doc'></div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/transformers/latest/doc/html/Control-Monad-Trans-RWS-Lazy.html#v:execRWS'>execRWS</a> &#x2237; RWS r w s a &#x2192; r &#x2192; s &#x2192; (s, w)</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>transformers</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Control.Monad.Trans.RWS.Lazy</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>Evaluate a computation with the given initial state and environment, returning the final state and output, discarding the final value. \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/fgl/latest/doc/html/Data-Graph-Inductive-Example.html#v:genUNodes'>genUNodes</a> &#x2237; Int &#x2192; [UNode]</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>fgl</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Graph.Inductive.Example</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>generate list of unlabeled nodes \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/fgl/latest/doc/html/Data-Graph-Inductive-Example.html#v:genLNodes'>genLNodes</a> &#x2237; Enum a &#x21D2; a &#x2192; Int &#x2192; [LNode a]</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>fgl</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Graph.Inductive.Example</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>generate list of labeled nodes \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/containers/latest/doc/html/Data-Map-Lazy.html#v:elemAt'>elemAt</a> &#x2237; Int &#x2192; Map k a &#x2192; (k, a)</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>containers</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Map.Lazy</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>O(log n). Retrieve an element by its index, i.e. by its zero-based index in the sequence sorted by keys. If the index is out of range (less than zero, greater or equal to size of the map), error is called.\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-code'>> elemAt 0 (fromList [(5,\"a\"), (3,\"b\")]) == (3,\"b\")\n",
"> elemAt 1 (fromList [(5,\"a\"), (3,\"b\")]) == (5, \"a\")\n",
"> elemAt 2 (fromList [(5,\"a\"), (3,\"b\")]) Error: index out of range \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/text/latest/doc/html/Data-Text.html#v:breakOnAll'>breakOnAll</a> &#x2237; Text &#x2192; Text &#x2192; [(Text, Text)]</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>text</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Text</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>O(n+m) Find all non-overlapping instances of needle in haystack. Each element of the returned list consists of a pair:\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>* The entire string prior to the kth match (i.e. the prefix)\n",
"</div>\n",
"<div class='hoogle-text'>* The kth match, followed by the remainder of the string\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>Examples:\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-code'>> breakOnAll \"::\" \"\"\n",
"> ==> []\n",
"> breakOnAll \"/\" \"a/b/c/\"\n",
"> ==> [(\"a\", \"/b/c/\"), (\"a/b\", \"/c/\"), (\"a/b/c\", \"/\")]\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>In (unlikely) bad cases, this function's time complexity degrades towards O(n*m).\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>The needle parameter may not be empty. \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/text/latest/doc/html/Data-Text-Lazy.html#v:breakOnAll'>breakOnAll</a> &#x2237; Text &#x2192; Text &#x2192; [(Text, Text)]</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>text</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Text.Lazy</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>O(n+m) Find all non-overlapping instances of needle in haystack. Each element of the returned list consists of a pair:\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>* The entire string prior to the kth match (i.e. the prefix)\n",
"</div>\n",
"<div class='hoogle-text'>* The kth match, followed by the remainder of the string\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>Examples:\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-code'>> breakOnAll \"::\" \"\"\n",
"> ==> []\n",
"> breakOnAll \"/\" \"a/b/c/\"\n",
"> ==> [(\"a\", \"/b/c/\"), (\"a/b\", \"/c/\"), (\"a/b/c\", \"/\")]\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>This function is strict in its first argument, and lazy in its second.\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>In (unlikely) bad cases, this function's time complexity degrades towards O(n*m).\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>The needle parameter may not be empty. \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/transformers/latest/doc/html/Control-Monad-Trans-RWS-Lazy.html#v:execRWST'>execRWST</a> &#x2237; Monad m &#x21D2; RWST r w s m a &#x2192; r &#x2192; s &#x2192; m (s, w)</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>transformers</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Control.Monad.Trans.RWS.Lazy</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>Evaluate a computation with the given initial state and environment, returning the final state and output, discarding the final value. \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/fgl/latest/doc/html/Data-Graph-Inductive-Query-BFS.html#v:level'>level</a> &#x2237; Graph gr &#x21D2; Node &#x2192; gr a b &#x2192; [(Node, Int)]</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>fgl</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Graph.Inductive.Query.BFS</span>)</span><div class='hoogle-doc'></div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/fgl/latest/doc/html/Data-Graph-Inductive-Query-Dominators.html#v:iDom'>iDom</a> &#x2237; Graph gr &#x21D2; gr a b &#x2192; Node &#x2192; [(Node, Node)]</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>fgl</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Graph.Inductive.Query.Dominators</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>return immediate dominators for each node of a graph, given a root \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/syb/latest/doc/html/Data-Generics-Twins.html#v:gmapAccumT'>gmapAccumT</a> &#x2237; Data d &#x21D2; (&#x2200; e. Data e &#x21D2; a &#x2192; e &#x2192; (a, e)) &#x2192; a &#x2192; d &#x2192; (a, d)</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>syb</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Data.Generics.Twins</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>gmapT with accumulation \n",
"</div>\n",
"</div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/HTTP/latest/doc/html/Network-BufferType.html#v:buf-95-span'>buf_span</a> &#x2237; BufferOp a &#x2192; (Char &#x2192; Bool) &#x2192; a &#x2192; (a, a)</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>HTTP</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Network.BufferType</span>)</span><div class='hoogle-doc'></div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/HTTP/latest/doc/html/Network-BufferType.html#v:buf-95-splitAt'>buf_splitAt</a> &#x2237; BufferOp a &#x2192; Int &#x2192; a &#x2192; (a, a)</span><span class='hoogle-sub'>(<span class='hoogle-head'>package</span> <span class='hoogle-package'>HTTP</span>, <span class='hoogle-head'>module</span> <span class='hoogle-module'>Network.BufferType</span>)</span><div class='hoogle-doc'></div>\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":hoogle :: [a] -> [(a, b)]"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"If you need a refresher on all of the options, you can just use `:help`:"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"The following commands are available:\n",
" :extension <Extension> - Enable a GHC extension.\n",
" :extension No<Extension> - Disable a GHC extension.\n",
" :type <expression> - Print expression type.\n",
" :info <name> - Print all info for a name.\n",
" :hoogle <query> - Search for a query on Hoogle.\n",
" :doc <ident> - Get documentation for an identifier via Hogole.\n",
" :set -XFlag -Wall - Set an option (like ghci).\n",
" :option <opt> - Set an option.\n",
" :option no-<opt> - Unset an option.\n",
" :?, :help - Show this help text.\n",
"\n",
"Any prefix of the commands will also suffice, e.g. use :ty for :type.\n",
"\n",
"Options:\n",
" lint enable or disable linting.\n",
" svg use svg output (cannot be resized).\n",
" show-types show types of all bound names\n",
" show-errors display Show instance missing errors normally.\n",
" pager use the pager to display results of :info, :doc, :hoogle, etc."
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":help"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"All of the code you normally put into IHaskell is (like in GHCi) interpreted. However, sometimes you've perfected a function, and now need it to run faster. In that case, you can go ahead and define a module in a single cell. As long as your module has a module header along the lines of `module Name where`, IHaskell will recognize it as a module. It will create the file `A/B.hs`, compile it, and load it. "
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"-- If your code isn't running fast enough, you can just put it into a module.\n",
"module A.B where\n",
"\n",
"fib 0 = 1\n",
"fib 1 = 1\n",
"fib n = fib (n-1) + fib (n-2)"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"Note that the module is by default imported unqualified, as though you had typed `import A.B`."
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"10946"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
2014-01-30 16:30:21 -08:00
},
{
"data": {
"text/plain": [
"10946"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- The module is automatically imported unqualified.\n",
"print $ A.B.fib 20\n",
"print $ fib 20"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"Note that since a new module is imported, all previous bound identifiers are now unbound. For instance, we no longer have access to the `f` function from before:"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><span class='err-msg'>Not in scope: f</span>"
],
"text/plain": [
"Not in scope: f"
]
2014-06-11 21:02:30 -07:00
},
2014-01-30 16:30:21 -08:00
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"f 3"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"However, if you re-import this module with another import statement, the original implicit import goes away."
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"10946"
]
2014-06-11 21:02:30 -07:00
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/*\n",
"Custom IHaskell CSS.\n",
"*/\n",
"\n",
"/* Styles used for the Hoogle display in the pager */\n",
".hoogle-doc {\n",
" display: block;\n",
" padding-bottom: 1.3em;\n",
" padding-left: 0.4em;\n",
"}\n",
".hoogle-code {\n",
" display: block;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
"}\n",
".hoogle-text {\n",
" display: block;\n",
"}\n",
".hoogle-name {\n",
" color: green;\n",
" font-weight: bold;\n",
"}\n",
".hoogle-head {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-sub {\n",
" display: block;\n",
" margin-left: 0.4em;\n",
"}\n",
".hoogle-package {\n",
" font-weight: bold;\n",
" font-style: italic;\n",
"}\n",
".hoogle-module {\n",
" font-weight: bold;\n",
"}\n",
".hoogle-class {\n",
" font-weight: bold;\n",
"}\n",
"\n",
"/* Styles used for basic displays */\n",
".get-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" display: block;\n",
" white-space: pre;\n",
"}\n",
"\n",
".show-type {\n",
" color: green;\n",
" font-weight: bold;\n",
" font-family: monospace;\n",
" margin-left: 1em;\n",
"}\n",
"\n",
".mono {\n",
" font-family: monospace;\n",
" display: block;\n",
"}\n",
"\n",
".err-msg {\n",
" color: red;\n",
" font-style: italic;\n",
" font-family: monospace;\n",
" white-space: pre;\n",
" display: block;\n",
"}\n",
"\n",
"#unshowable {\n",
" color: red;\n",
" font-weight: bold;\n",
"}\n",
"\n",
".err-msg.in.collapse {\n",
" padding-top: 0.7em;\n",
"}\n",
"\n",
"/* Code that will get highlighted before it is highlighted */\n",
".highlight-code {\n",
" white-space: pre;\n",
" font-family: monospace;\n",
"}\n",
"\n",
"/* Hlint styles */\n",
".suggestion-warning { \n",
" font-weight: bold;\n",
" color: rgb(200, 130, 0);\n",
"}\n",
".suggestion-error { \n",
" font-weight: bold;\n",
" color: red;\n",
"}\n",
".suggestion-name {\n",
" font-weight: bold;\n",
"}\n",
"</style><span class='err-msg'>Not in scope: fib<br/>Perhaps you meant Fib.fib (imported from A.B)</span>"
],
"text/plain": [
"Not in scope: fib\n",
"Perhaps you meant Fib.fib (imported from A.B)"
]
},
"metadata": {},
"output_type": "display_data"
2014-01-30 16:30:21 -08:00
}
],
"source": [
"import qualified A.B as Fib\n",
"\n",
"Fib.fib 20\n",
"fib 20"
]
},
{
"cell_type": "markdown",
"metadata": {
"hidden": false
},
"source": [
"Thanks!\n",
"---\n",
"\n",
"That's it for now! I hope you've enjoyed this little demo of **IHaskell**! There are still a few features that I haven't covered, such as the `show-types` and `show-errors` options, as well as the relatively intelligent autocompletion mechanism and inline type info popups.\n",
"\n",
"I hope you find IHaskell useful, and please report any bugs or features requests [on Github](https://github.com/gibiansky/IHaskell/issues). If you have any comments, want to contribute, or just want to get in touch, don't hesitate to contact me at Andrew dot Gibiansky at Gmail. Contributions are also more than welcome, and I'm happy to help you get started with IHaskell development if you'd like to contribute!\n",
"\n",
"I am also often available at `#ihaskell` on IRC at `chat.freenode.net`, so if I'm around, don't hesitate to ask questions.\n",
"\n",
"Thank you to [Adam Vogt](https://github.com/aavogt), [Stian Håklev](http://reganmian.net/), and [@edechter](https://github.com/edechter) for their testing, bug reporting, pull requests, and general patience!"
]
2014-01-30 16:30:21 -08:00
}
],
"metadata": {
"kernelspec": {
"display_name": "Haskell",
"language": "haskell",
"name": "haskell"
},
"language_info": {
"name": "haskell",
"version": "7.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
2015-02-23 20:27:50 -05:00
}