Page 1

Working with Lists

(Recursion, pattern matching, testing list functions)

Page 2

Lists: recap

Page 3

List Syntax

Page 4

How is the list type defined?

Page 5

The List type, defined

Page 6

Polymorphic list functions and their types

Page 7

List functions for specific types

Page 8

Live Demo

Let's look at some illustrative examples...

Page 9

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 10

A pitfall which QuickCheck in GHCi

Page 11

Extended defaulting in GHCi

Page 12

Avoiding the pitfall which QuickCheck in GHCi

Testing polymorphic functions without falling into the pitfall