0% found this document useful (0 votes)
5 views5 pages

Lecture 19 - Higher Order Functions III

Higher Order Functions

Uploaded by

DA BEST
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

Lecture 19 - Higher Order Functions III

Higher Order Functions

Uploaded by

DA BEST
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Further Programming Paradigms

Lecture 19: Higher Order Functions III - Verification

Dr Martin Barrere, University of Surrey

(Slides designed by Prof. Paul Krause, University of Surrey)


Verification and general functions

With higher-order polymorphic functions we are interested in proving equalities


between functions, and not just between values
We can also prove theorems that are general and reusable.
Consider the following two function definitions:
twice :: (a -> a) -> (a -> a)
twice f = f.f
And
iter :: Int -> (a -> a) -> (a -> a)
iter n f
| n > 0 = f.iter (n-1) f
| otherwise = id

• Claim: iter is a generalisation of twice. How do we prove that?


Function level Verification

We need to prove: iter 2 f = twice f


iter 2 f
= f . iter 1 f by (iter.1)
= f . (f . iter 0 f) by (iter.1)
= f . (f . id) by (iter.2)
= f . f by (compId)
= twice f by (twice.1)
Where we have used:
f . id = f (compId)
Which is true since:
(f . id) x
= f (id x)
= f x

So, for any argument x the two functions have the same behaviour
Principle of extensionality

This is saying that:


• two functions f and g are the equal if they have the same value at every
argument
This is a black box concept of equality
Contrast this with intensionality where two functions are the same only if they
have the same definitions
• We look inside the functions to make sure the mechanisms are the same
From a mathematical point of view we are only interested in the values given by
function
• Of course, if we are interested in efficiency then the way in which the value
is obtained will be important
Where to now?

• You will explore this material further in the lab class this afternoon

• It should be enough to give you an overview of this paradigm

• We are not trying to get you to be expert functional programmers

• But before we complete this part of the module, we will take a quick look at the
support for “programming in the real world”

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy