Reputation: 1437
I have to write a function that sums the cubes of a list of numbers.
This is my code so far:
cube' :: (Num a) => a -> a
cube' x = x*x*x
mySum :: (Num a) => [a] -> a
mySum [] = []
mySum xs = foldr (\acc x -> acc + cube'(x)) 0 xs
The problem is that when I run it I get the following error:
No instance for (Num[t0]) arising from a use of 'it'
In a stmt of an interactive GHCI command: print it
Upvotes: 0
Views: 705
Reputation: 30227
You're definitely on the right track. As bhelkir points out in a comment, the first clause of the definition is wrong and unnecessary. The other problem is that you have the argument order wrong for the lambda.
Upvotes: 1