Haskell function that applies a list of functions to a list of inputs?
As commented your recursion fails to recurse in the second argument, so the definition would be
apply (f:fs) (x:xs) = (f x) : (apply fs xs)
apply _ _ = []
You can go point-free with
apply = zipWith ($) -- zipWith id works too as @Redu commented
Or even more interesting, you can go applicativelly-crazy with ZipList
import Control.Applicative
apply f x = getZipList $ ZipList f <*> ZipList x
It's interesting that in two comments are two totally valid answers:
applyAll' :: [b -> c] -> [b] -> [c]
applyAll = zipWith ($)
and
applyAll :: [a -> c] -> [a] -> [c]
applyAll' = zipWith id
It's also interesting that Haskell, due to its way to pick types (type inference), changes a little bit its signature, obviously they are equivalent.
id
and $
functions are equivalents when id
is restricted to functions. (As Robin pointed out in his comment).