COM2001: Abstract Data Types
1. A software designer has been asked to create a new data type called Library for a Haskellbased libraryloan system.1 The following algebraic data types have already been defined;
they represent the librarys books, readers a
Mike Stannett (m.stannett@dcs.shef.ac.uk)
Each data type T has its own Principle of
Structural Induction.
"Given a predicate P over T, if we want to prove
P(t) holds for all finite t : T, it is enough to
prove"
Special cases, like P(infty), need to be
con
How much work does your program do?
When is one algorithm better than another?
Why might throwing extra people at a project
that is running late make it even later?
When is one algorithm better than another?
Is quicksort quick? How quick?
What is a combin
COM2001 Advanced Programming Topics
Blackadder ITC TrueType Font
There appear to be many sorts of algebraic
data type in Haskell, but Haskell treats them
all the same way
data RGB = Red  Green  Blue
data Block = Sides Float Float Float
data Encapulate a
Constraint Propagation and
Typing
1
COM2001 ADVANCED PROGRAMMING TOPICS
Type declarations
2
Recall that Haskell lets you declare many kinds
of type, but theyre all treated the same way
data RGB = Red  Green  Blue
data Block = Sides Float Float Float
da
COM2001
Advanced Programming Techniques
Mike Stannett (m.stannett@dcs.shef.ac.uk)
Department of Computer Science
The University of Sheffield
Spring Semester
ABSTRACT DATA TYPES, PROGRAM
COMPLEXITY, AND CORRECTNESS
Some basic questions
How do we know whet
Proof Techniques
MATHEMATICAL INDUCTION
PROOF BY CONTRADICTION
STRUCTURAL INDUCTION
Mathematical induction
0 & + 1
()
Given a predicate P(n) over natural numbers n
In order to prove that P(n) holds for every n
It is enough to prove
P(0)
P(k) > P(k+1)
P
Program Proof
COM2001 Advanced Programming Topics
Mike Stannett (m.stannett@dcs.shef.ac.uk)
Is it correct?
ADTs can be used to
describe behaviour
If Imp has the behaviour
described by Spec, it is
correct
But how do we establish
correctness?
Youve look
Exercises on Induction
The Principle of Mathematical Induction says, of any predicate
P (n),
If you want to prove that P (n) holds for every integer n 0,
You should first prove P (0) (the Base Case), and then
Regardless of the value of n, show that if
COM2001: Program Proof and Structural Induction
1. Consider the following Haskell definitions.
data LinkedList a =
asRevList :
asRevList ll
End
Link (x,l)
End  Link (a, LinkedList a)
LinkedList a > [a]
= case ll of
> []
> joinLists (asRevList l) [x]
