【发布时间】:2013-03-07 02:54:09
【问题描述】:
我正在尝试使用现有的 MapReduce 实现(Real World Haskell 中的那个)编写一个简单的程序。
作为使用框架的一个例子,下面是一些计算文件中单词数的代码:
module Main where
import Control.Monad (forM_)
import Data.Int (Int64)
import qualified Data.ByteString.Lazy.Char8 as LB
import System.Environment (getArgs)
import LineChunks (chunkedReadWith)
import MapReduce (mapReduce, rdeepseq)
wordCount :: [LB.ByteString] -> Int
wordCount = mapReduce rdeepseq (length . LB.words)
rdeepseq sum
main :: IO ()
main = do
args <- getArgs
forM_ args $ \path -> do
numWords <- chunkedReadWith wordCount path
putStrLn $ "Words: " ++ show numWords
我需要使用相同的 MapReduce 框架来编写一个程序来搜索一些字符串(比如“il”),并返回找到它们的行号。例如,输出可能是:
verILy: found on lines 34, 67, 23
ILlinois: found on lines 1, 2, 56
vILla: found on lines 4, 5, 6
(“il”不需要大写。)
我是 Haskell 初学者,还没有任何具体的想法。我确实注意到 Data.ByteString.Lazy.Char8 类有一个成员函数findIndices。这个可以用吗?
任何正确方向的代码或提示将不胜感激。
【问题讨论】:
-
我会先尝试使用列表haskell.org/ghc/docs/latest/html/libraries/base/Data-List.html 来解决它,然后看看是否可以使用mapreduce。
-
谢谢。但是,我需要专门使用 MapReduce,所以如果有人可以帮助我,那就太好了!
标签: haskell