08.08.07

Exercise 9.7

Posted in Uncategorized at 11:13 pm by admin

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.

1 Comment »

  1. J said,

    January 11, 2010 at 7:51 pm

    More concisely:

    twice f = f . f

Leave a Comment