Beginning to learn Haskell:
*Main> map double [1,2,3]
[2,4,6]
*Main> sum (map double [1,2,3])
12
*Main> (sum . map) (double) ([1,2,3])
<interactive>:71:8:
Couldn't match type ‘[b0] -> [b0]’ with ‘[[t0] -> t]’
Expected type: (b0 -> b0) -> [[t0] -> t]
Actual type: (b0 -> b0) -> [b0] -> [b0]
Relevant bindings include it :: t (bound at <interactive>:71:1)
Probable cause: ‘map’ is applied to too few arguments
In the second argument of ‘(.)’, namely ‘map’
In the expression: sum . map
According to this answer: Haskell: difference between . (dot) and $ (dollar sign) "The primary purpose of the . operator is not to avoid parenthesis, but to chain functions. It lets you tie the output of whatever appears on the right to the input of whatever appears on the left.".
OK, so why my example does not work? Actual and expected types are different, but why? After all, according to this description map
should take (double) ([1,2,3])
on the input and pass its output to sum
's input?