# 08.08.07

## Exercise 9.7

twice :: (a -> a) -> a -> a twice f = (\x -> f (f x)) |

`twice twice` applies the function 4 times:

twice twice f = twice (\y -> f (f y)) = (\x -> (\y -> f (f y)) ((\y -> f (f y)) x)) = (\x -> (\y -> f (f y)) (f (f x))) = (\x -> f (f (f (f x)))) |

`twice twice twice` and `twice (twice twice)` each apply the function 16 times.

J said,

January 11, 2010 at 7:51 pm

More concisely:

twice f = f . f