我正在尝试对Real World Haskell第24章中的程序进行一些简单的修改。这里有一些代码可以计算文件中的行数:
import qualified Data.ByteString.Lazy.Char8 as LB
lineCount :: [LB.ByteString] -> Int64
lineCount = mapReduce rdeepseq (LB.count '\n')
rdeepseq sum
我正在尝试编写一些计算文件中单词的代码。这就是我想出的:
import qualified Data.ByteString.Lazy.Char8 as LB
lineCount :: [LB.ByteString] -> Int64
lineCount = mapReduce rdeepseq (length LB.words)
rdeepseq sum
但是,我得到了:
Couldn't match expected type `LB.ByteString -> b0'
with actual type `Int'
In the return type of a call of `length'
Probable cause: `length' is applied to too many arguments
In the second argument of `mapReduce', namely `(length LB.words)'
In the expression:
mapReduce rdeepseq (length LB.words) rdeepseq sum
可能是什么问题?
答案 0 :(得分:1)
您希望将length
应用于调用LB.words
的结果,而不是LB.words
该函数。试试(length . LB.words)
。