"In addition to displaying outputs in a rich format, IHaskell has a bunch of useful features.\n",
"metadata": {},
"\n",
"output_type": "display_data",
"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:"
"text": [
]
"/Users/silver"
]
}
],
"prompt_number": 28
},
},
{
{
"cell_type": "code",
"cell_type": "code",
...
@@ -1124,7 +1111,14 @@
...
@@ -1124,7 +1111,14 @@
]
]
}
}
],
],
"prompt_number": 16
"prompt_number": 26
},
{
"cell_type": "markdown",
"metadata": {},
"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",
"cell_type": "code",
...
@@ -1137,7 +1131,7 @@
...
@@ -1137,7 +1131,7 @@
"language": "python",
"language": "python",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"prompt_number": 19
"prompt_number": 27
},
},
{
{
"cell_type": "code",
"cell_type": "code",
...
@@ -1157,7 +1151,44 @@
...
@@ -1157,7 +1151,44 @@
]
]
}
}
],
],
"prompt_number": 20
"prompt_number": 28
},
{
"cell_type": "markdown",
"metadata": {},
"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",
"collapsed": false,
"input": [
":doc filterM"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 35
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Like with `:info`, the Hoogle directives use the IPython"
]
},
{
"cell_type": "markdown",
"metadata": {},
"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",
"cell_type": "code",
...
@@ -1173,15 +1204,20 @@
...
@@ -1173,15 +1204,20 @@
"language": "python",
"language": "python",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"prompt_number": 21
"prompt_number": 29
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the module is by default imported unqualified, as though you had typed `import A.B`."
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"collapsed": false,
"collapsed": false,
"input": [
"input": [
"-- The module is automatically imported unqualified.\n",
"-- The module is automatically imported unqualified.\n",
"-- Note that since a new module is imported, all previous\n",
"-- bound identifiers are now unbound.\n",
"print $ A.B.fib 20\n",
"print $ A.B.fib 20\n",
"print $ fib 20"
"print $ fib 20"
],
],
...
@@ -1203,13 +1239,48 @@
...
@@ -1203,13 +1239,48 @@
]
]
}
}
],
],
"prompt_number": 22
"prompt_number": 32
},
{
"cell_type": "markdown",
"metadata": {},
"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",
"collapsed": false,
"input": [
"f 3"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span class='err-msg'>Not in scope: `f'</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"Not in scope: `f'"
]
}
],
"prompt_number": 33
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"However, if you re-import this module with another import statement, the original implicit import goes away."
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"collapsed": false,
"collapsed": false,
"input": [
"input": [
"-- But if you re-import it qualified, the previous import goes away.\n",