Page 1

Collections of things: Tuples and Lists

A first taste!

Page 2

Tuples

examplePair :: (Double, Bool)
examplePair = (3.14, False)

exampleTriple :: (Bool, Int, String)
exampleTriple = (False, 42, "Answer")

exampleFunction :: (Bool, Int, String) -> Bool
exampleFunction (b,n,s) = not b && length s < n
Page 3

Lists

Page 4
Lists
Page 5

List notation

Page 6

Functions over lists 1

Page 7

Functions over lists

Primitive recursion is the mosts common form when defining list functions from scratch

 -- doubles [3,6,10] = [6,12,20]
doubles :: [Integer] -> [Integer]
doubles [] = (...)
doubles (x:xs) = (...)
Page 8
Functions over lists
Page 9

map

 -- map f [x1,x2,...,xn] = [f x1,f x2,...,f cn]
map f [] = ...
map f (x:xs) = ...
Page 10
map
Page 11

filter

Another predefined list function

Page 12

List comprehensions

Page 13
List comprehensions
Page 14

Further example