Docsity

Proving Equalities of Function Composition and Currying in Haskell - Prof. James L. Caldwe, Assignments of Computer Science

Toggle sidebar
bg1
HW 4 Prof. Caldwell
Due: 9 September 2008 COSC 3015
1
In class we discussed the following code.
plus (x,y) = x + y
plusc x y = x + y
curry f x y = f(x,y)
uncurry f (x,y) = f x y
(f . g) x = f (g x)
id x = x
Recall the extensionality rule for proving functions f, g :Aโ†’Bare equal.
f=gdef
=โˆ€x:A. fx =gx
We gave a proof in class of the following identity.
Lemma 1.1. For every function fwhere f:: Aโ†’B, the following equality holds
f. id =f
Proof: To show these functions are equal, by extensionality, we must show that
โˆ€x:A.(f . id)x=f x
Choose an arbitrary xโˆˆAand show (f . id)x=f x. Starting on the left side:
(f. id)xhhdef .of (.)ii
=f(id x)hhdef.of idii
=f x
So the identity holds.
๎˜ƒ
Following the proofs given in class, prove the following equalities using extensionality.
Problem 1.1.
i.) curry plus = plusc
ii.) curry (uncurry plusc) = plusc
iii.) uncurry (curry plus) = plus
Problem 1.2. Haskell has a built-in function called flip having the following type:
(a->b->c)->b->a->c
Write a bit of Haskell code that has this type.
1

Partial preview of the text

Download Proving Equalities of Function Composition and Currying in Haskell - Prof. James L. Caldwe and more Assignments Computer Science in PDF only on Docsity!

HW 4 Prof. Caldwell Due: 9 September 2008 COSC 3015

In class we discussed the following code.

plus (x,y) = x + y plusc x y = x + y curry f x y = f(x,y) uncurry f (x,y) = f x y (f. g) x = f (g x) id x = x

Recall the extensionality rule for proving functions f, g : A โ†’ B are equal.

f = g def = โˆ€x : A. f x = gx

We gave a proof in class of the following identity.

Lemma 1.1. For every function f where f :: A โ†’ B, the following equality holds

f. id = f

Proof: To show these functions are equal, by extensionality, we must show that

โˆ€x : A.(f. id)x = f x

Choose an arbitrary x โˆˆ A and show (f. id)x = f x. Starting on the left side:

(f. id) x ใ€ˆใ€ˆdef. of (.)ใ€‰ใ€‰ = f (id x) ใ€ˆใ€ˆdef. of idใ€‰ใ€‰ = f x

So the identity holds.  Following the proofs given in class, prove the following equalities using extensionality.

Problem 1.1. i.) curry plus = plusc ii.) curry (uncurry plusc) = plusc iii.) uncurry (curry plus) = plus

Problem 1.2. Haskell has a built-in function called flip having the following type:

(a -> b -> c) -> b -> a -> c

Write a bit of Haskell code that has this type.