I have a question regarding the type signatures in Haskell, which I find sometimes a bit difficult to unterstand. For example the type signature of zipWith
is:
zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
What I see here is that zipWith
expects a function (with parameters of type a
and b
), a list with a
s, a list with b
s and it gives us a list of c
s. But I do not unterstand why I can use zipWith
with (+)
for example, which has the signature:
(+) :: a -> a -> a
From my point of view the signature of (+)
doesn't match with the signature of (a -> b -> c)
. (+)
only expects parameters of type a
, while (a -> b -> c)
expects parameters of different types: a
and b
. Can anyone give me a hint what is my fault?
zipWith
function is that it "lifts" a function of two arguments to the list monad since the signature could be written aszipWith :: (a -> b -> c) -> ([a] -> [b] -> [c])
. In the case of(+) :: Int -> Int -> Int
,a ~ Int
,b ~ Int
, andc ~ Int
, sozipWith (+) :: [Int] -> [Int] -> [Int]
. – bheklilr