0

I'm trying to make some simple modifications to a program from Real World Haskell Chapter 24. Here's some code that counts the number of lines in a file:

import qualified Data.ByteString.Lazy.Char8 as LB
lineCount :: [LB.ByteString] -> Int64
lineCount = mapReduce rdeepseq (LB.count '\n')
                      rdeepseq sum

I'm trying to write some code that counts the words in the file. Here's what I came up with:

import qualified Data.ByteString.Lazy.Char8 as LB
lineCount :: [LB.ByteString] -> Int64
lineCount = mapReduce rdeepseq (length LB.words)
                      rdeepseq sum

However, I get:

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

What could be the problem?

4

1 回答 1

1

You want to apply length to the result of calling LB.words, not to LB.words the function. Try (length . LB.words).

于 2013-03-03T04:54:10.357 回答