Page 1

Abstract Data Types

Efficiency of purely functional data structures

Page 2

Efficiency of reverse

Page 3

Testing it in GHCi

Page 4

Faster Reverse

Page 5

Faster Reverse example

Page 6

Testing it in GHCi again

Page 7

Data Structures

Page 8

What is a Queue?

Page 9

A Queue interface

data Q a                    -- the type of queues

empty   :: Q a              -- an empty queue
add     :: a -> Q a -> Q a  -- add an element at the back

isEmpty :: Q a -> Bool      -- check if the queue is empty
front   :: Q a -> a         -- inspect the front element
remove  :: Q a -> Q a       -- remove an element from the front
Page 10

First Queue implementation

Page 11

Simple Queue efficiency?

Page 12

New idea: use two lists

Page 13

First attempt

Page 14

Smart constructor

Page 15


Page 16

Queue Efficiency

Page 17

Queue Equality

Page 18

Modules and abstract data types

Modules can be used to hide implementation details

Page 19

About Export lists

Page 20

Correctness and testing