中工作我是Haskell的新手,所以这个问题对于大多数Haskell程序员来说应该是相当平凡的: 我有一个函数digits :: Integer -> [Int]
它转换一个整数到它的数字列表(123到[1,2,3])。现在得到这些数字的总和,我输入sum $ digits 123
ghci,一切正常,它输出6.然而,当我在一个文件中创建如下函数时,我收到一个错误。这可能与ghci推断123的类型有关,但这还不够,所以我可以解决这个问题。无法匹配`[Int]'Integer - > Int'但在GHCI
在一个文本文件中的函数:
digitalSum :: Integer -> Int
digitalSum = sum $ digits
和错误:
* 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
另见:[* Haskell:区别。 (点)和$(美元符号)*](http://stackoverflow.com/q/940382/2751851) – duplode