title |
---|
Applied Haskell Syllabus |
Applied Haskell is a commercial training programming focusing on teaching intermediate Haskell. The goal is to help someone move from knowing Haskell basics to being able to write commercial software, with enough knowledge to pick up any new skills needed on demand.
If you're new to Haskell, please check out our learning page for introductory material.
The content below is freely available. If you're interested in participating in a class teaching this material, please check out our training page.
If you're not participating in a instructor-led course, feel free to skip this section.
This course is typically taught over a two day period by an FP Complete Haskell engineer. There is more material available here than can be taught in two days, so some content is typically skipped in the classroom, with student interest guiding what we focus on. This course also has a one day subset.
In order to maximize the value of this course, we strongly recommend that you:
- Ensure you meet the prerequisites mentioned below
- Set up your system before attending the class following the instructions below
- At least skim through the material below before the course
- Perform the exercises during the course
- Take time after the course to review the material again and take another crack at any exercises you were not successful at
You should already be comfortable with Haskell syntax, common control structures, and typeclasses. For the most part: if you understand how to use monads, you're ready for this course. Though we'll cover it in more detail during the course, you should also read all about strictness, as experience has shown this to be a topic that trips people up often.
As a self test, we recommend ensuring you're able to do the following:
- Define
fmap
in terms of>>=
andreturn
- Define
fmap
in terms of<*>
andpure
- Define
>>=
in terms ofApplicative
instance andjoin
- Define
join
in terms of>>=
- Explain the intuition behind: what can you do with
Monad
and notApplicative
?
If you're looking to read up on this, our recommendations are:
- Haskell Programming from First Principles for a thorough coverage of all relevant topics
- For a quick crash course on
Functor
/Applicative
/Monad
, see Michael's blog post
Let the course material begin!
We will be using the Stack build tool extensively throughout this course. To get your system set up:
-
Download and install Stack following our Getting Started guide. If you already have Stack installed, run
stack upgrade
to ensure you have the latest version. -
We're going to be using LTS Haskell version 12.21. (We'll explain what LTS Haskell is in the material below.) You may as well install an unnecessarily broad number of packages right off the bat:
$ stack build --resolver lts-12.21 classy-prelude-yesod lens rio yesod-test foldl microlens-platform wai-conduit hspec`
- You may also find it convenient to run
stack config set resolver lts-12.21
from outside of a project to set your global resolver to match.
- You may also find it convenient to run
-
Make sure you can run the script below successfully. Save it to a file ending with
.hs
and then runstack filename.hs
. On non-Windows systems, you can also dochmod +x filename.hs && ./filename.hs
#!/usr/bin/env stack -- stack --resolver lts-12.21 script main = putStrLn "Hello World!"
Note that the comment on line 2 above is necessary!
We'll start off with a high level overview of the content we're going to cover, our approach to Haskell, and tooling to be aware of.
The rio
library codifies much of our recommended best practices. It
includes an approach to structuring applications, a standard library,
a Prelude replacement, and more.
Haskell is immutable-by-default, but that default can be overridden. And this mutability oftens pops up in the context of concurrency. This is one of Haskell's greatest strengths, and we'll cover it now.
One of the hallmarks of Haskell is lazy evaluation. Understanding how this works, when to use strictness, and how to avoid space leaks are vital to production quality Haskell code.
Lists are a common data structure in Haskell, but they are often overused. It's vital to understand other common data structures. This section intentionally comes after the strictness section, as the former is a prerequisite for this material.
- Data Structures
- String Types
- Containers
- Vector
- Builders and difference lists
- Let's revisit that data structure quiz...
Exceptions are built into the Haskell runtime. Proper handling is essential.
That tutorial references two other deeper dives on the topic:
You must test your code. Haskell strong types help immensely, but they are not a replacement for testing. Fortunately, Haskell has great testing libraries and tools.
- The hspec test framework
- QuickCheck
Serialization to external binary and text-based formats.
- typed-process for launching and interacting with subprocesses
- HTTP client library
- Web services
- Command line argument parsing optparse-applicative
- cryptonite
- time
- Random number generation
Deeper understanding of Haskell performance, and how to improve it.
This section demonstrates some common Haskell coding patterns, how they work, when they're useful, and possible pitfalls.
- Covariance, contravariance, and positive and negative position
- Continuation Passing Style
- Constraint trick for instances; perhaps we can have a section for common type patterns (newtypes an obvious one, and also for example using Rank-N types to store a generic function in a data structure, versus existential types to store generic data).