I am new to Haskell so this question should be fairly trivial to most Haskell programmers:
I've got a function digits :: Integer -> [Int]
which converts an integer to a list of its digits (123 to [1,2,3]). To now get the sum of those digits I enter sum $ digits 123
in ghci and everything works, it outputs 6. As soon as I create the function in a file as follows, however, I get an error. It probably has to do with the fact that ghci infers a type for 123, but that is not enough so I can fix the problem.
The function in a text file:
digitalSum :: Integer -> Int
digitalSum = sum $ digits
and the error:
* Couldn't match type `[Int]' with `Integer -> Int'
Expected type: Integer -> Integer -> Int
Actual type: Integer -> [Int]
* In the second argument of `($)', namely `digits'
In the expression: sum $ digits
In an equation for `digitalSum': digitalSum = sum $ digits