IHaskell/Haskell-Notebook.ipynb
2013-12-22 01:05:02 -05:00

691 lines
15 KiB
Plaintext

{
"metadata": {
"language": "haskell",
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"data X = X Int\n",
" | Y String\n",
" | Z Float\n",
" deriving Show\n",
" \n",
"let values = [X 20,\n",
" Y \"Test\",\n",
" Z 0.5]\n",
"mapM_ print values"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"text": [
"X 20\n",
"Y \"Test\"\n",
"Z 0.5"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import Control.Applicative\n",
"print 1\n",
"print $ (+) <$> Just 3 <*> Just 10"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"text": [
"1"
]
},
{
"metadata": {},
"output_type": "display_data",
"text": [
"Just 13"
]
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import Control.Monad\n",
"forM [1, 2, 3, 4] $ \\x -> do\n",
" print (x * x)\n",
" return (-x)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"text": [
"1\n",
"4\n",
"9\n",
"16\n",
"[-1,-2,-3,-4]"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"1"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"text": [
"1"
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import Prelude"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ma"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span style='color: red; font-style: italic;'>Not in scope: `ma'<br/>Perhaps you meant one of these:<br/> `map' (imported from Prelude), `max' (imported from Prelude)</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"Not in scope: `ma'\n",
"Perhaps you meant one of these:\n",
" `map' (imported from Prelude), `max' (imported from Prelude)"
]
}
],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"f 3 = 2\n",
"f 2 = 3"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"f 2"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"text": [
"3"
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data X = Y Int\n",
"return (Y 3)\n",
"Y 3"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span style='color: red; font-style: italic;'>No instance for (Num String)<br/> arising from the literal `3'<br/>Possible fix:<br/> add an instance declaration for (Num String)</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"No instance for (GHC.Num.Num GHC.Base.String)\n",
" arising from the literal `3'\n",
"Possible fix:\n",
" add an instance declaration for (GHC.Num.Num GHC.Base.String)"
]
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data X = Y Int"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 14
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data X = Y Int deriving Show"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 18
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"Y 3"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span style='color: red; font-style: italic;'>No instance for (Num String)<br/> arising from the literal `3'<br/>Possible fix:<br/> add an instance declaration for (Num String)</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"No instance for (GHC.Num.Num GHC.Base.String)\n",
" arising from the literal `3'\n",
"Possible fix:\n",
" add an instance declaration for (GHC.Num.Num GHC.Base.String)"
]
}
],
"prompt_number": 19
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"test [] = 10"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 20
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"test [3]"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span style='color: red; font-style: italic;'><interactive>:1:1-12: Non-exhaustive patterns in function test</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<interactive>:1:1-12: Non-exhaustive patterns in function test"
]
}
],
"prompt_number": 21
},
{
"cell_type": "code",
"collapsed": false,
"input": [
":tadaf"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span style='color: red; font-style: italic;'>Parse error (line 1, column 1): Unknown directive: 'tadaf'.</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"Parse error (line 1, column 1): Unknown directive: 'tadaf'."
]
}
],
"prompt_number": 22
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"f :: Int -> Int\n",
"f 10 = 11\n",
"f 11 = 10\n",
"f 10"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"text": [
"11"
]
}
],
"prompt_number": 23
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data X = Y Int"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 24
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"let x = 11\n",
" z = 10 in\n",
" x+z"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"text": [
"21"
]
}
],
"prompt_number": 25
},
{
"cell_type": "code",
"collapsed": false,
"input": [
":extension OverloadedStrings"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import Prelude hiding (div, id)\n",
"import Text.Blaze.Html4.Strict hiding (map, style)\n",
"import Text.Blaze.Html4.Strict.Attributes\n",
"import Control.Monad\n",
"div ! style \"color: red\" $ do\n",
" p \"This is an example of BlazeMarkup syntax.\"\n",
" p \"Hello\"\n",
" b \"Hello\"\n",
" img ! src \"/static/base/images/ipynblogo.png\" ! width \"200\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<div style=\"color: red\">\n",
" <p>\n",
" This is an example of BlazeMarkup syntax.\n",
" </p>\n",
" <p>\n",
" Hello\n",
" </p>\n",
" <b>\n",
" Hello\n",
" </b>\n",
" <img src=\"/static/base/images/ipynblogo.png\" width=\"200\">\n",
"</div>\n"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<div style=\"color: red\">\n",
" <p>\n",
" This is an example of BlazeMarkup syntax.\n",
" </p>\n",
" <p>\n",
" Hello\n",
" </p>\n",
" <b>\n",
" Hello\n",
" </b>\n",
" <img src=\"/static/base/images/ipynblogo.png\" width=\"200\">\n",
"</div>"
]
}
],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"forM_ [100, 200, 300, 400, 500, 600, 700, 800] $ \\size -> do\n",
" let s = show size\n",
" unsafePerformIO $ do\n",
" threadDelay 100000\n",
" putStrLn $ \"Generating size: \" ++ s\n",
" return $ img ! src \"/static/base/images/ipynblogo.png\" ! width (toValue s)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span style='color: red; font-style: italic;'>Not in scope: `unsafePerformIO'<br/>Not in scope: `threadDelay'</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"Not in scope: `unsafePerformIO'\n",
"Not in scope: `threadDelay'"
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import System.IO.Unsafe"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import Prelude hiding (head, id, div)\n",
"import Text.Blaze.Html4.Strict hiding (map)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 34
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data X = Y Int\n",
"Y 3"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span style='color: red; font-style: italic;'>No instance for (Show X)<br/> arising from a use of `print'<br/>Possible fix:<br/> add an instance declaration for (Show X)</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"No instance for (GHC.Show.Show :Interactive.X)\n",
" arising from a use of `System.IO.print'\n",
"Possible fix:\n",
" add an instance declaration for (GHC.Show.Show :Interactive.X)"
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"forM [1] $ \\x -> return (Y x)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 59
},
{
"cell_type": "code",
"collapsed": false,
"input": [
":t forM [1] $ \\x -> return (Y x)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span style='font-weight: bold; color: green;'>forall (m :: * -> *). Monad m => m [X]</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"forall (m :: * -> *). Monad m => m [X]"
]
}
],
"prompt_number": 60
},
{
"cell_type": "code",
"collapsed": false,
"input": [
":t (Y 3)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span style='font-weight: bold; color: green;'>X</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"X"
]
}
],
"prompt_number": 61
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import Control.Concurrent\n",
"import Control.Monad\n",
"\n",
"forM_ [1..10] $ \\x -> do \n",
" print x\n",
" threadDelay 100000"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"text": [
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"9\n",
"10"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"3"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"text": [
"3"
]
}
],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"data Thing = One Int | Two String deriving Show\n",
"One 3"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span style='color: red; font-style: italic;'>No instance for (Show Thing)<br/> arising from a use of `print'<br/>Possible fix:<br/> add an instance declaration for (Show Thing)</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"No instance for (GHC.Show.Show :Interactive.Thing)\n",
" arising from a use of `System.IO.print'\n",
"Possible fix:\n",
" add an instance declaration for (GHC.Show.Show :Interactive.Thing)"
]
}
],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"Two \"hello\""
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "display_data",
"text": [
"Two \"hello\""
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"One 3"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"<span style='color: red; font-style: italic;'>No instance for (Show Thing)<br/> arising from a use of `print'<br/>Possible fix:<br/> add an instance declaration for (Show Thing)</span>"
],
"metadata": {},
"output_type": "display_data",
"text": [
"No instance for (GHC.Show.Show :Interactive.Thing)\n",
" arising from a use of `System.IO.print'\n",
"Possible fix:\n",
" add an instance declaration for (GHC.Show.Show :Interactive.Thing)"
]
}
],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}