0
我想對真正的世界哈斯克爾第24章中的程序做一些簡單的修改。下面是一些計算文件中行數的代碼:修改真實世界Haskell程序來計算字數和行數使用MapReduce
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
可能是什麼問題呢?
謝謝,但不幸的是,這是行不通的。現在出現錯誤: – 2013-03-03 14:57:13
實際類型爲'Int'的預期類型'Int64'不匹配 預期類型:[Int] - > Int64 實際類型:[Int] - > Int 在'mapReduce ',即'sum' 在表達式中: mapReduce rdeepseq(length。LB.words)rdeepseq sum – 2013-03-03 14:57:33
哦,等等,它在我將函數改成lineCount :: [LB.ByteString] - > Int而不是lineCount時起作用: :[LB.ByteString] - > Int64。謝謝! – 2013-03-03 14:59:53