Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell tuple function composition

I have started learning Haskell from Introduction to FP using Haskell by Richard Bird, but I am stuck in proving the following:

pair (f, g) . h = pair (f . h, g . h)

The definitions of pair is the following:

pair :: (a -> b, a -> c) -> a -> (b, c)
pair (f, g) x = (f x, g x)

Could someone point me in the right direction? Please keep in mind that I am only at the beginning. Thanks in advance!

like image 677
Paul Herman Avatar asked Dec 04 '25 10:12

Paul Herman


2 Answers

One way is to expand all definitions. Remember that f . g = \x -> f (g x) and f a b = ... is the same as f a = \b -> ....

So you can try to expand definitions of pair and . in pair (f, g) . h = pair (f . h, g . h)

like image 163
nponeccop Avatar answered Dec 07 '25 09:12

nponeccop


You can use extensionality, i.e., if two functions give the same result when acting on any x, then they are considered the same (as pure functions - they may have different code and hence different time/space usage).

So in this case, you could take the equality you're trying to prove, act with each side on some x of the appropriate type, and show you obtain the same result in both cases.

like image 37
Fixnum Avatar answered Dec 07 '25 09:12

Fixnum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!