I'm out of my element a bit. I've been using higher order functions and I'm trying to apply a function AND use (.) to combine functions. I'm trying to write a function total that applies the function (first argument) to every element in the list (second argument) and sums the result.
I was given a specific type definition (which I'm not supposed to change) and I'm trying to map the function f to a list and then sum the returned list.
total :: (Int -> Int) -> [Int] -> Int
total f x = sum x . map f x
I should get an Int that's the sum of the total. I get an error but it's one I'm unfamiliar with:
* Couldn't match expected type `Int' with actual type `[Int] -> c0'
* Probable cause: `(.)' is applied to too few arguments
In the expression: sum x . map f
In an equation for `total': total f x = sum x . map f
I need direction. I don't understand why . should be applied to more arguments.
.to composemap f x, but that is a list, not a function, so it does not compose with.. The error "applied to too few arguments" is due to.returning a function (f . gis the function obtained by composing functionfand functiong), but the type oftotalclaims to return anInt. So, GHC wonders if the function resulting from.should be applied to some argument which you forgot. This is not the issue in your code, but this is why GHC generated that message.