Page 1

Working with Lists

(Recursion, pattern matching, testing list functions)

Page 2

Datatypes: recap

Page 3
Datatypes: recap

Recursive datatypes

Page 4
Datatypes: recap

Pattern matching

Page 5

Lists: recap

Page 6

The List type, defined

Page 7

List Syntax

Page 8

Polymorphic list functions and their types

Page 9

List functions for specific types

Page 10

Live Demo

Let's look at some illustrative examples...

Page 11

Example: "Quicksort"

qsort :: Ord a => [a] -> [a]
qsort [] = []
qsort (x1:xs) = qsort smaller ++ [x1] ++ qsort bigger
  where
    smaller = [x | x<-xs, x<=x1]
    bigger  = [x | x<-xs, x>x1]
Page 12

A pitfall which QuickCheck in GHCi

Page 13

Extended defaulting in GHCi

Page 14

Avoiding the pitfall which QuickCheck in GHCi

Testing polymorphic functions without falling into the pitfall