Interactive code snippets not yet available for SoH 2.0, see our Status of of School of Haskell 2.0 blog post

# Learning Haskell at the SoH

1 Nov 2013

### Sections

The main page of the School of Haskell contains a list of tutorials, courses, and articles that are carefully picked by us. If you're new to Haskell, you might want to look into one of the beginner courses. We also have some in-depth courses and a changing selection of recent articles.

What is different about our tutorials and articles is that authors are able to embed active Haskell snippets in them. If you see a snippet like this:

``````factorial 0 = 1
factorial n = n * factorial (n - 1)

main = print (factorial 4)``````

you may click on the Run button and the code will be executed right there on the spot. Try it!

Being able to see the code running is fun, but real learning begins when you start modifying code. Try editing something inside the snippet. The safe edit would be to change the number 4 to something else. Try it and run the resulting program. The answer changes! If you make a mistake, the code won't compile and you will see a compiler error.

## Hidden Gems

Many authors include exercises in their content. They often provide a skeleton of the code you're supposed to modify as well as the solution to the exercise. But for those who want to go through the process of solving the exercise (a highly recommended practice), seeing the solution would spoil the pleasure. That's why solutions are usually hidden from view. You can reveal the hidden text by pressing the down arrow.

### Exercise

This definition of `factorial` doesn't work for negative numbers. Fix it so that a runtime error is emitted when `factorial` is called with an invalid argument.

``````factorial 0 = 1
factorial n = n * factorial (n - 1)

main = print (factorial (-2)) -- will cause stack overflow``````

## Active Web

Sometimes you will see web snippets, like this one, written in Yesod:

``````{-# LANGUAGE TypeFamilies, QuasiQuotes, MultiParamTypeClasses,
import Yesod

data MyWebSite = MyWebSite

instance Yesod MyWebSite

mkYesod "MyWebSite" [parseRoutes|
/ HomeR GET
|]

-- show
getHomeR = defaultLayout \$ do
[whamlet|
<h2> Things To Do
<ul>
<li> Write a killer app
<li> Create a startup
<li> Go public
|]
toWidget [cassius|
body
background-color: #edf
|]
-- /show
main = warpEnv MyWebSite``````

When you run it, you actually start a web server whose output is displayed in a frame under the snippet. Try it! As before, you can edit the snippet in place and try small modifications.

The web frame that displays the web page you are serving has additional buttons that let you reload the site, view it in a separate window, or close the pane.