IHaskell/notebooks/IHaskell.ipynb
Thomas Peiselt afb05614f4 Revert "Update notebook: hoogle response changed."
This reverts commit 31a59439ac059e8852f712c2176b22115d93457e.
2018-11-01 21:43:09 +01:00

2575 lines
113 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"![](https://camo.githubusercontent.com/f6540337202bb3b0c2545d90de0791c9196f9510/68747470733a2f2f7261772e6769746875622e636f6d2f67696269616e736b792f494861736b656c6c2f6d61737465722f68746d6c2f6c6f676f2d36347836342e706e67)\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 [Jupyter](https://jupyter.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,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"8"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"\"Hello, World!\""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- First of all, we can evaluate simple expressions.\n",
"3 + 5\n",
"\"Hello, \" ++ \"World!\""
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"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,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"\"Hello, World!\""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"it1"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"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,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"\"Hello, World!\""
]
},
"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": {
"deletable": true,
"editable": true
},
"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,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"100"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"12"
]
},
"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": {
"deletable": true,
"editable": true
},
"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,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"\"What's going on?\""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"print \"What's going on?\""
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"IHaskell supports most GHC extensions via the `:extension` directive (or any shorthand thereof)."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
"<style>/* 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",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\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'>&lt;interactive&gt;:1:1: error:<br/> • Thing has no constructors (EmptyDataDecls permits this)<br/> • In the data declaration for Thing</span>"
],
"text/plain": [
"<interactive>:1:1: error:\n",
" • Thing has no constructors (EmptyDataDecls permits this)\n",
" • In the data declaration for Thing"
]
},
"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,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"-- And enable extensions.\n",
":ext EmptyDataDecls\n",
"data Thing"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"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,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"[A \"Hello\",B 10]"
]
},
"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": {
"deletable": true,
"editable": true
},
"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,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
"<style>/* 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",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\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"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- We can look at types like in GHCi.\n",
":ty 3 + 3"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"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,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- What is the Integral typeclass?\n",
":info Integral"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"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,
"deletable": true,
"editable": 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,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/* 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",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\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",
" {-# MINIMAL quotRem, toInteger #-}\n",
" \t-- Defined in GHC.Real\n",
"instance Integral Word -- Defined in GHC.Real\n",
"instance Integral Integer -- Defined in GHC.Real\n",
"instance Integral Int -- Defined in GHC.Real\n",
"</textarea></form></div><script>CodeMirror.fromTextArea(document.getElementById('code'), {mode: 'haskell', readOnly: 'nocursor'});</script>"
],
"text/plain": [
"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",
" {-# MINIMAL quotRem, toInteger #-}\n",
" \t-- Defined in GHC.Real\n",
"instance Integral Word -- Defined in GHC.Real\n",
"instance Integral Integer -- Defined in GHC.Real\n",
"instance Integral Int -- Defined in GHC.Real"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":info Integral"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"We can now write slightly more complicated scripts."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"1\n",
"2\n",
"3\n",
"4\n",
"5"
]
},
"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": {
"deletable": true,
"editable": true
},
"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,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"data Color = Red | Green | Blue"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"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,
"deletable": true,
"editable": true
},
"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": {
"deletable": true,
"editable": true
},
"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,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
"<style>/* 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",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\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>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/* 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",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\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>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/* 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",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\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>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Red\n",
"Green\n",
"Blue"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"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."
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"The `ihaskell-aeson` package adds a display for [Aeson](http://hackage.haskell.org/package/aeson) JSON `Value` types. These are automatically formatted as JSON, rather than as Haskell values:"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"null"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"true"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"{\n",
" \"x\": 3,\n",
" \"y\": 2\n",
"}"
]
},
"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": {
"deletable": true,
"editable": true
},
"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": 18,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
"<style>/* 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",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\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>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/* 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",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\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\">"
]
},
"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": {
"deletable": true,
"editable": true
},
"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": 19,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAIAAAD2HxkiAAAABmJLR0QA/wD/AP+gvaeTAAAXMElEQVR4nO3dWXAU1R4G8O6ZyZAoIAWoyL5IFShaWqWlZRX6YOkbD76il9LCCTNZCGEJBjFsYQ0QgbCrIISghB0ETCgWAdmXQBIIIQsJkZCQQNZJz9J9H2LFVJZJp/t0nz493+/p3gt89ffgd7szPfMffsyYMePHj+cAgIZz587Zxo8fv2XLFtqTAASp8PBwC+0ZAIIdSghAGUoIQBlKCEAZSghAGUoIQBlKCEAZSghAGUoIQBlKCEAZSghAGUoIQBlKCEAZSghAGUoIQBlKCEAZSghAGUoIQBlKCEAZSghAGUoIQBlKCEAZSghAGUoIQBlKCEAZSghAGUoIQBlKCEAZSghAGUoIQBlKCEAZSghAGUoIQBlKCEAZSghAG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JClAuYXp6epuftm022969e5GMZBaTlaFZwqampiFDhrRfnDxw4ECVi5ORjGT9kxWj+Y6ZpKSkDhcnV1VVrVq1CslIZitZFSpXwkePHoWGhnY2kt1uLykpQTKSWUlWg9qVMPDiZI7jFC9ORjKS9U9WS/8r4cWLF+XsbD137hySkWz8ZJUovDAjiuI777zT5ftxrVbruHHj/H4/kpFs5GT1KJTw119/bXlEE5jdbt+xYweSkWzkZPX0LmFdXV2/fv3knEWzvn371tTUIBnJxkwmQu8XZpYsWVJfXy//9zc0NCxbtgzJSDZmMjG6XQkLCwtl3hK0ZrPZ8vPzkYxkoyWTouvt6IQJE5RtL58wYQKSkWy0ZFL0K+GpU6fU7GzNyMhAMpKNk0yQTiX0+XxjxoxRs7389ddf93q9SEayEZLJ0qmEGzZsUHBL0Jrdbt+4cSOSkWyEZLL0KGF1dXXv3r3VnEWzXr16PX36FMlIpptMnB6PKBISEgRBUJ/j8XgWLFiAZCTTTdaEplfCu3fvEtwYabVas7OzkYxkWsla0Px29NNPP1XwlKYzISEhH3/8MZKRTCtZC9qW8MiRI8QXJ9tstqNHjyIZyfona1QTDUsoCMLw4cPb7BFQj+f5wYMHDxs2DMlI1jN5yJAhTU1NWjRFww3cKSkpxcXFISEhZE9EkqRHjx5xHIdkJOuZXFpaun79eo2+9V6rEgqCoNHnlC9dusRx3IcffohkJOuWzHEckZdbO6RVCePj4zVKBjAZA30/IUBwQgkBKEMJAShDCQEoQwkBKEMJAShDCQEoQwkBKEMJAShDCQEoQwkBKEMJAShDCQEoQwkBKEMJAShDCQEoQwkBKEMJAShDCQEoQwkBKEMJAShDCQEoQwkBKEMJAShDCQEoQwkBKEMJAShDCQEoQwkBKEMJAShDCQEoQwkBKEMJAShDCQEoQwkBKEMJAShDCQEoQwkBKEMJAShDCQEoQwkBKEMJAShDCQEo48eMGTN+/HjaYwAEqXPnzv0fXuhGu5+B2XIAAAAASUVORK5CYII="
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- We can draw diagrams, right in the notebook.\n",
":extension NoMonomorphismRestriction FlexibleContexts TypeFamilies\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": {
"deletable": true,
"editable": true
},
"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": 20,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAcIAAAEsCAIAAADfNCTgAAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVR4nO3deVxU5f4H8M/AsKOAu7iz5BKCikuoaAjm1bSUgDIlzSVvmnVdytSbYl3tVm645X5xx6Vc+uVyXTA1S3HD1JsLIosrKKgg2zDn98fUhDADA2dmziyf98s/hnOeec53Bvp01ueRCYIAIiKqLhupCyAiMm+MUSIiURijRESiMEaJiERhjBIRicIYNTOyUmxtbevUqdO3b99jx45V6e1hYWE6tl+/fn1MTExMTIzIfnQne56Hh0ffvn1//vlnvW+ogq2b8vdDpkggs6Lxl2hnZ5eYmKj720NDQ3XcXGhoqMa/k6r2ozuNH1Aulx85ckTv29K2dVP+fsgEcW/ULKn++3zy5MnHH38MoLi4eNWqVcYsQPXXc+jQIQP1r/qABQUF69evB6BQKGbOnGmgbRmCob8fMimMUTNWo0aN6dOnq16np6erl6enp48YMaJRo0b29vZNmzb96KOPnjx5orGHmzdvhoeHt2jRwtnZ2dHRsW3btosWLRL+3J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JiERhjBIRicIYJSIShTFKRCQKY5SISBTGKBGRKIxRIiJRGKNERKIwRomIRGGMEhGJwhglIhKFMUpEJApjlIhIFMYoEZEojFEiIlEYo0REojBGiYhEYYwSEYnCGCUiEoUxSkQkCmOUiEgUxigRkSiMUSIiURijRESiMEaJiERhjBIRicIYJSIShTFKRCQKY5SISBTGKBGRKIxRIiJRGKNERKIwRomIRGGMEhGJwhglIhKFMUpEJApjlIhIFMYoEZEojFEiIlH+HxoqMQB1jhqbAAAAAElFTkSuQmCC"
},
"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": {
"deletable": true,
"editable": true
},
"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": 21,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
"<style>/* 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",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\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;\">Redundant do</div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">Found:</div><div class=\"highlight-code\" id=\"haskell\">do return 3</div></div><div class=\"suggestion-row\" style=\"float: left;\"><div class=\"suggestion-warning\">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: Redundant do\n",
"Found:\n",
"do return 3\n",
"Why not:\n",
"return 3"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"4"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"3"
]
},
"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",
"do\n",
" return 3"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"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": 22,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"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": 23,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"-- You could similarly use `:opt lint` to turn it back on.\n",
"f $ 3"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"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": 24,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/* 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",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\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"
],
"text/plain": [
"filterM :: Monad m => (a -> m Bool) -> [a] -> m [a]\n",
"URL: http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html#v:filterM\n",
"This generalizes the list-based filter function."
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":doc filterM"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"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": 25,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<style>/* 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",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\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/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/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/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/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/fgl/latest/doc/html/Data-Graph-Inductive-Internal-Thread.html#v:threadList'>threadList</a> &#x2237; (Collect r c) &#x2192; (Split t i r) &#x2192; [i] &#x2192; t &#x2192; (c, t)</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.Internal.Thread</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-Internal-Thread.html#v:threadList-39-'>threadList'</a> &#x2237; (Collect r c) &#x2192; (Split t i r) &#x2192; [i] &#x2192; t &#x2192; (c, t)</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.Internal.Thread</span>)</span><div class='hoogle-doc'></div>\n",
"<span class='hoogle-name'><a target='_blank' href='http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString-Lazy.html#v:mapAccumL'>mapAccumL</a> &#x2237; (acc &#x2192; Word8 &#x2192; (acc, Word8)) &#x2192; acc &#x2192; ByteString &#x2192; (acc, ByteString)</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.Lazy</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a ByteString, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new ByteString. \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.html#v:mapAccumL'>mapAccumL</a> &#x2237; (acc &#x2192; Word8 &#x2192; (acc, Word8)) &#x2192; acc &#x2192; ByteString &#x2192; (acc, ByteString)</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</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a ByteString, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new list. \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.html#v:mapAccumR'>mapAccumR</a> &#x2237; (acc &#x2192; Word8 &#x2192; (acc, Word8)) &#x2192; acc &#x2192; ByteString &#x2192; (acc, ByteString)</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</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>The mapAccumR function behaves like a combination of map and foldr; it applies a function to each element of a ByteString, passing an accumulating parameter from right to left, and returning a final value of this accumulator together with the new ByteString. \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-Lazy-Char8.html#v:mapAccumL'>mapAccumL</a> &#x2237; (acc &#x2192; Char &#x2192; (acc, Char)) &#x2192; acc &#x2192; ByteString &#x2192; (acc, ByteString)</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.Lazy.Char8</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a ByteString, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new ByteString. \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-Char8.html#v:mapAccumL'>mapAccumL</a> &#x2237; (acc &#x2192; Char &#x2192; (acc, Char)) &#x2192; acc &#x2192; ByteString &#x2192; (acc, ByteString)</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.Char8</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a ByteString, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new list. \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-Char8.html#v:mapAccumR'>mapAccumR</a> &#x2237; (acc &#x2192; Char &#x2192; (acc, Char)) &#x2192; acc &#x2192; ByteString &#x2192; (acc, ByteString)</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.Char8</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>The mapAccumR function behaves like a combination of map and foldr; it applies a function to each element of a ByteString, passing an accumulating parameter from right to left, and returning a final value of this accumulator together with the new ByteString. \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:mapAccumL'>mapAccumL</a> &#x2237; (a &#x2192; Char &#x2192; (a, Char)) &#x2192; a &#x2192; Text &#x2192; (a, 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) Like a combination of map and foldl'. Applies a function to each element of a Text, passing an accumulating parameter from left to right, and returns a final Text. Performs replacement on invalid scalar values. \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:mapAccumR'>mapAccumR</a> &#x2237; (a &#x2192; Char &#x2192; (a, Char)) &#x2192; a &#x2192; Text &#x2192; (a, 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'>The mapAccumR function behaves like a combination of map and a strict foldr; it applies a function to each element of a Text, passing an accumulating parameter from right to left, and returning a final value of this accumulator together with the new Text. Performs replacement on invalid scalar values. \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: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/bytestring/latest/doc/html/Data-ByteString.html#v:breakSubstring'>breakSubstring</a> &#x2237; ByteString &#x2192; ByteString &#x2192; (ByteString, ByteString)</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</span>)</span><div class='hoogle-doc'><div class='hoogle-text'>otherwise -> Just (length x) </pre>\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>For example, to tokenise a string, dropping delimiters:\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-code'>> tokenise x y = h (:) if null t then [] else tokenise x (drop (length x) t)\n",
"> \n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>To skip to the first occurence of a string:\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-code'>> snd (breakSubstring x y)\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>To take the parts of a string before a delimiter:\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-code'>> fst (breakSubstring x y) \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:breakOn'>breakOn</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 the first instance of needle (which must be non-null) in haystack. The first element of the returned tuple is the prefix of haystack before needle is matched. The second is the remainder of haystack, starting with the match.\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'>> breakOn \"::\" \"a::b::c\" ==> (\"a\", \"::b::c\")\n",
"> breakOn \"/\" \"foobar\" ==> (\"foobar\", \"\")\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>Laws:\n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-code'>> append prefix match == haystack\n",
"> \n",
"</div>\n",
"<div class='hoogle-text'></div>\n",
"<div class='hoogle-text'>If you need to break a string by a substring repeatedly (e.g. you want to break on every instance of a substring), use breakOnAll instead, as it has lower startup overhead.\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>\n"
],
"text/plain": [
"zip :: [a] -> [b] -> [(a, b)]\n",
"URL: http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:zip\n",
"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",
"(>*<) :: Monoidal f => f a -> f b -> f (a, b)\n",
"URL: http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString-Builder-Prim.html#v:-62--42--60-\n",
"A pairing/concatenation operator for builder primitives, both bounded and fixed size.\n",
"\n",
"For example,\n",
"\n",
"> toLazyByteString (primFixed (char7 >*< char7) ('x','y')) = \"xy\"\n",
"\n",
"We can combine multiple primitives using >*< multiple times.\n",
"\n",
"> toLazyByteString (primFixed (char7 >*< char7 >*< char7) ('x',('y','z'))) = \"xyz\" \n",
"shrinkState :: ShrinkState s a => a -> s -> [(a, s)]\n",
"URL: http://hackage.haskell.org/packages/archive/QuickCheck/latest/doc/html/Test-QuickCheck-Modifiers.html#v:shrinkState\n",
"\n",
"breakOnAll :: Text -> Text -> [(Text, Text)]\n",
"URL: http://hackage.haskell.org/packages/archive/text/latest/doc/html/Data-Text.html#v:breakOnAll\n",
"O(n+m) Find all non-overlapping instances of needle in haystack. Each element of the returned list consists of a pair:\n",
"\n",
"* The entire string prior to the kth match (i.e. the prefix)\n",
"* The kth match, followed by the remainder of the string\n",
"\n",
"Examples:\n",
"\n",
"> breakOnAll \"::\" \"\"\n",
"> ==> []\n",
"> breakOnAll \"/\" \"a/b/c/\"\n",
"> ==> [(\"a\", \"/b/c/\"), (\"a/b\", \"/c/\"), (\"a/b/c\", \"/\")]\n",
"\n",
"In (unlikely) bad cases, this function's time complexity degrades towards O(n*m).\n",
"\n",
"The needle parameter may not be empty. \n",
"breakOnAll :: Text -> Text -> [(Text, Text)]\n",
"URL: http://hackage.haskell.org/packages/archive/text/latest/doc/html/Data-Text-Lazy.html#v:breakOnAll\n",
"O(n+m) Find all non-overlapping instances of needle in haystack. Each element of the returned list consists of a pair:\n",
"\n",
"* The entire string prior to the kth match (i.e. the prefix)\n",
"* The kth match, followed by the remainder of the string\n",
"\n",
"Examples:\n",
"\n",
"> breakOnAll \"::\" \"\"\n",
"> ==> []\n",
"> breakOnAll \"/\" \"a/b/c/\"\n",
"> ==> [(\"a\", \"/b/c/\"), (\"a/b\", \"/c/\"), (\"a/b/c\", \"/\")]\n",
"\n",
"This function is strict in its first argument, and lazy in its second.\n",
"\n",
"In (unlikely) bad cases, this function's time complexity degrades towards O(n*m).\n",
"\n",
"The needle parameter may not be empty. \n",
"genLNodes :: Enum a => a -> Int -> [LNode a]\n",
"URL: http://hackage.haskell.org/packages/archive/fgl/latest/doc/html/Data-Graph-Inductive-Example.html#v:genLNodes\n",
"generate list of labeled nodes \n",
"gmapAccumT :: Data d => (forall e. Data e => a -> e -> (a, e)) -> a -> d -> (a, d)\n",
"URL: http://hackage.haskell.org/packages/archive/syb/latest/doc/html/Data-Generics-Twins.html#v:gmapAccumT\n",
"gmapT with accumulation \n",
"threadList :: (Collect r c) -> (Split t i r) -> [i] -> t -> (c, t)\n",
"URL: http://hackage.haskell.org/packages/archive/fgl/latest/doc/html/Data-Graph-Inductive-Internal-Thread.html#v:threadList\n",
"\n",
"threadList' :: (Collect r c) -> (Split t i r) -> [i] -> t -> (c, t)\n",
"URL: http://hackage.haskell.org/packages/archive/fgl/latest/doc/html/Data-Graph-Inductive-Internal-Thread.html#v:threadList-39-\n",
"\n",
"mapAccumL :: (acc -> Word8 -> (acc, Word8)) -> acc -> ByteString -> (acc, ByteString)\n",
"URL: http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString-Lazy.html#v:mapAccumL\n",
"The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a ByteString, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new ByteString. \n",
"mapAccumL :: (acc -> Word8 -> (acc, Word8)) -> acc -> ByteString -> (acc, ByteString)\n",
"URL: http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString.html#v:mapAccumL\n",
"The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a ByteString, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new list. \n",
"mapAccumR :: (acc -> Word8 -> (acc, Word8)) -> acc -> ByteString -> (acc, ByteString)\n",
"URL: http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString.html#v:mapAccumR\n",
"The mapAccumR function behaves like a combination of map and foldr; it applies a function to each element of a ByteString, passing an accumulating parameter from right to left, and returning a final value of this accumulator together with the new ByteString. \n",
"mapAccumL :: (acc -> Char -> (acc, Char)) -> acc -> ByteString -> (acc, ByteString)\n",
"URL: http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString-Lazy-Char8.html#v:mapAccumL\n",
"The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a ByteString, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new ByteString. \n",
"mapAccumL :: (acc -> Char -> (acc, Char)) -> acc -> ByteString -> (acc, ByteString)\n",
"URL: http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString-Char8.html#v:mapAccumL\n",
"The mapAccumL function behaves like a combination of map and foldl; it applies a function to each element of a ByteString, passing an accumulating parameter from left to right, and returning a final value of this accumulator together with the new list. \n",
"mapAccumR :: (acc -> Char -> (acc, Char)) -> acc -> ByteString -> (acc, ByteString)\n",
"URL: http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString-Char8.html#v:mapAccumR\n",
"The mapAccumR function behaves like a combination of map and foldr; it applies a function to each element of a ByteString, passing an accumulating parameter from right to left, and returning a final value of this accumulator together with the new ByteString. \n",
"mapAccumL :: (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)\n",
"URL: http://hackage.haskell.org/packages/archive/text/latest/doc/html/Data-Text.html#v:mapAccumL\n",
"O(n) Like a combination of map and foldl'. Applies a function to each element of a Text, passing an accumulating parameter from left to right, and returns a final Text. Performs replacement on invalid scalar values. \n",
"mapAccumR :: (a -> Char -> (a, Char)) -> a -> Text -> (a, Text)\n",
"URL: http://hackage.haskell.org/packages/archive/text/latest/doc/html/Data-Text.html#v:mapAccumR\n",
"The mapAccumR function behaves like a combination of map and a strict foldr; it applies a function to each element of a Text, passing an accumulating parameter from right to left, and returning a final value of this accumulator together with the new Text. Performs replacement on invalid scalar values. \n",
"execRWS :: RWS r w s a -> r -> s -> (s, w)\n",
"URL: http://hackage.haskell.org/packages/archive/transformers/latest/doc/html/Control-Monad-Trans-RWS-Lazy.html#v:execRWS\n",
"Evaluate a computation with the given initial state and environment, returning the final state and output, discarding the final value. \n",
"breakSubstring :: ByteString -> ByteString -> (ByteString, ByteString)\n",
"URL: http://hackage.haskell.org/packages/archive/bytestring/latest/doc/html/Data-ByteString.html#v:breakSubstring\n",
"otherwise -> Just (length x) </pre>\n",
"\n",
"For example, to tokenise a string, dropping delimiters:\n",
"\n",
"> tokenise x y = h (:) if null t then [] else tokenise x (drop (length x) t)\n",
"> \n",
"\n",
"To skip to the first occurence of a string:\n",
"\n",
"> snd (breakSubstring x y)\n",
"\n",
"To take the parts of a string before a delimiter:\n",
"\n",
"> fst (breakSubstring x y) \n",
"breakOn :: Text -> Text -> (Text, Text)\n",
"URL: http://hackage.haskell.org/packages/archive/text/latest/doc/html/Data-Text.html#v:breakOn\n",
"O(n+m) Find the first instance of needle (which must be non-null) in haystack. The first element of the returned tuple is the prefix of haystack before needle is matched. The second is the remainder of haystack, starting with the match.\n",
"\n",
"Examples:\n",
"\n",
"> breakOn \"::\" \"a::b::c\" ==> (\"a\", \"::b::c\")\n",
"> breakOn \"/\" \"foobar\" ==> (\"foobar\", \"\")\n",
"\n",
"Laws:\n",
"\n",
"> append prefix match == haystack\n",
"> \n",
"\n",
"If you need to break a string by a substring repeatedly (e.g. you want to break on every instance of a substring), use breakOnAll instead, as it has lower startup overhead.\n",
"\n",
"In (unlikely) bad cases, this function's time complexity degrades towards O(n*m)."
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":hoogle :: [a] -> [b] -> [(a, b)]"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"If you need a refresher on all of the options, you can just use `:help`:"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"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."
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
":help"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"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": 27,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"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": {
"deletable": true,
"editable": true
},
"source": [
"Note that the module is by default imported unqualified, as though you had typed `import A.B`."
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"10946"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"10946"
]
},
"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": {
"deletable": true,
"editable": true
},
"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": 29,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/html": [
"<style>/* 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",
".get-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"display: block;\n",
"white-space: pre-wrap;\n",
"}\n",
".show-type {\n",
"color: green;\n",
"font-weight: bold;\n",
"font-family: monospace;\n",
"margin-left: 1em;\n",
"}\n",
".mono {\n",
"font-family: monospace;\n",
"display: block;\n",
"}\n",
".err-msg {\n",
"color: red;\n",
"font-style: italic;\n",
"font-family: monospace;\n",
"white-space: pre;\n",
"display: block;\n",
"}\n",
"#unshowable {\n",
"color: red;\n",
"font-weight: bold;\n",
"}\n",
".err-msg.in.collapse {\n",
"padding-top: 0.7em;\n",
"}\n",
".highlight-code {\n",
"white-space: pre;\n",
"font-family: monospace;\n",
"}\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'>&lt;interactive&gt;:1:1: error: Variable not in scope: f :: Integer -&gt; t</span>"
],
"text/plain": [
"<interactive>:1:1: error: Variable not in scope: f :: Integer -> t"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"f 3"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"However, if you re-import this module with another import statement, the original implicit import goes away."
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"text/plain": [
"10946"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"10946"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import qualified A.B as Fib\n",
"\n",
"Fib.fib 20\n",
"fib 20"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"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",
"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!"
]
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Haskell",
"language": "haskell",
"name": "haskell"
},
"language_info": {
"codemirror_mode": "ihaskell",
"file_extension": ".hs",
"name": "haskell",
"version": "8.0.2"
},
"latex_envs": {
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 0
},
"nav_menu": {},
"toc": {
"navigate_menu": true,
"number_sections": true,
"sideBar": true,
"threshold": 6,
"toc_cell": false,
"toc_section_display": "block",
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 0
}