Lists, patterns and recursion
Lists are the first data structure of Haskell, and recursion replaces the loops of an imperative language. These fifteen lessons cover cons and append, ranges and comprehensions, pattern matching, where and let, and a recursion that carries an accumulator. The higher-order functions follow: map, filter, the two folds, and the sorting and searching of Data.List. Operator fixity and composition close the part.
2.1
Lists: cons, append and the total helpers
[] and :, ++, head and tail, length, null, reverse, why append is expensive
Open
2.2
Ranges and enumeration
[1..10], [1,3..9], [10,9..1], infinite ranges, enumFromThenTo
Open
2.3
List comprehensions
a generator, a guard, let in a comprehension, nested generators, a Pythagorean triple
Open
2.4
Pattern matching
function equations, the wildcard, as-patterns, list patterns, a match the compiler warns about
Open
2.5
case expressions
case of, matching a Maybe, nesting, case against equations
Open
2.6
where, let and scope
where on a definition, let in, let in do, the scope of each
Open
2.7
Recursion replaces loops
a base case, a recursive step, sum, product, replicate, the call stack
Open
2.8
Tail recursion and accumulators
an accumulator, go helpers, why a tail call still builds thunks
Open
2.9
map, filter, zipWith and flip
functions as arguments, map, filter, zipWith, flip, any and all
Open
2.10
Currying, partial application and sections
one argument at a time, partial application, operator sections, lambdas
Open
2.11
Operators, precedence and fixity
precedence, associativity, backticks, infixl and infixr, an operator of your own
Open
2.12
(.), ($) and point-free code
composition, $, flip ($), a pipeline, where point-free stops helping
Open
2.13
foldr, foldl and foldl'
the two folds, foldr1, foldl' from Data.List, a fold written by hand
Open
2.14
Sorting, searching and deduplication
sort, sortBy, nub, elem, lookup, minimum and maximum
Open
2.15
Splitting and joining text
words, unwords, lines, unlines, break, span, a word count
Open