Okay hi guys, I am having a weird problem.
hist :: [Int] -> [Int]
hist x = (foldr (+) 0 x)
The code above does not work, because trying to compile I am getting the error, that expected type '[Int]' could not be matched with actual type 'Int'. I don't get that.
Fun Fact: when I delete the signature, the function works fine! Does anybody know the fault?
Thank you!
foldr (+) 0 :: Num a => [a] -> a
. When you omit the type signature, the correct type forhist
is inferred. If you want to specify a concrete type, it should be[Int] -> Int
. – chepnerfoldr (+) 0
? (You can ask GHCi if you're not sure.) – Robin Zigmond