2018-11-10 16:44
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

Strings and type synonyms

Page 9

Polymorphic list functions and their types

Page 10

List functions for specific types

Page 11

Live Demo

Let's look at some illustrative examples...

Page 12

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 13

A pitfall which QuickCheck in GHCi

Page 14

Extended defaulting in GHCi

Page 15

Avoiding the pitfall which QuickCheck in GHCi

Testing polymorphic functions without falling into the pitfall