修改Real World Haskell程序,使用MapReduce计算单词和行数

时间:2013-03-03 03:04:56

标签: mapreduce haskell

我正在尝试对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

可能是什么问题?

1 个答案:

答案 0 :(得分:1)

您希望将length应用于调用LB.words的结果,而不是LB.words该函数。试试(length . LB.words)