The problem here is that the type of .
is (b->c) -> (a->b) -> a -> c
but our initial value for our fold is not a function. To put this in english, .
is function composition, but we want function application. This is easily solved however with ($)
.
($) f a = f a
so
applyAll :: [(f -> a)] -> a -> a
applyAll [f] v = foldr ($) v [f]
Next we have a problem with the [f]
part. All that does is match a single element list which is probably not what you want.
applyAll fs v = foldr ($) v fs
Now we need to deal with one last part, the type signature. Our function can't take in functions of type f -> a
because when we connect them we'll feed a function a value of type a
when it expects an f
. So the end result is
applyAll :: [a -> a] -> a -> a
applyAll fs v = foldr ($) v fs