Exercise 9.5

applyAll :: [(a -> a)] -> a -> a
applyAll [] x = x
applyAll (f:fs) x = f (applyAll fs x)

4 Responses to “Exercise 9.5”

  1. anonyoumous says:

    applyAll fs x = foldr id x fs

  2. anonymous says:

    applyAll fs x = foldr ($) x fs

  3. Kazu Yamamoto says:

    applyAll = foldr (.) id

  4. RJP says:

    id, ($), (.) and \ aren’t introduced until later in the text, using concepts only from 9.1 and earlier, one answer would be:

    applyAll :: [(a -> a)] -> a -> a
    applyAll = flip (foldr aux)
    where aux f x = f x

Leave a Reply