【发布时间】:2016-10-18 09:14:18
【问题描述】:
我想在 Haskell 的无限列表中找到第一个匹配的元素。
此代码正在运行:
findPassword passwordHash = (head . filter (checkPassword passwordHash)) allStrings
checkPassword 真的很长(因为它是 SHA1 哈希)
checkPassword hash string = (sha1 string) == hash
allStrings 只是所有可能字符串的列表:
allStrings = [ c : s | s <- "" : allStrings, c <- ['a'..'z'] ++ ['0'..'9'] ]
我希望这段代码并行运行,但如果我用 parFilter 替换过滤器:
import qualified Control.Parallel.Strategies as S
parFilter p = S.withStrategy (S.evalBuffer 1000 S.rseq) . filter p
它不起作用……你有什么想法吗?这段代码也使用了大量内存,但这是另一个问题。 完整的脚本在这里https://github.com/ThibaudDauce/habreaker
【问题讨论】:
-
你怎么知道它不起作用?
-
它永远运行并吃掉我所有的内存和处理器
标签: haskell parallel-processing infinite