小编Gui*_*ess的帖子

使haskell程序在(大致)内存中运行

我正在尝试接收CSV文件,错误检查它然后打印错误消息.

mapM_(appendFile filePath)(返回[string]的errorCheck函数)

这可以工作,但是当我运行它但在非常长的CSV上它会耗尽内存.我认为问题在于它过于懒惰,并且在它执行任何操作之前将整个CSV加载到内存中.我已尝试使用BangPatterns强制执行严格性但我不确定我是否正确使用它因为它没有帮助

我可以提供更多信息或代码,但我不确定与我的问题有什么关系

码:

main = do
    safeRead s = catch (readFile s) $ \_ -> return ""

    filePath <- safeRead "in.txt"
    file <- safeRead filePath

    --save the errors
    writeFile (createErrorFilePath filePath) (getFileName $ filePath ++ "\n")
    let !addToErr = do appendFile (createErrorFilePath filePath) 

    mapM_ addToErr (map ('\n':) (errorCheckFile (( \(Right x) -> x )  (parseCSV file)) (errorCheckCols (checkCols . head $ (( \(Right x) -> x )  (parseCSV file))) errorMsgs)))
    --exit with correct number
    exitWith . ExitFailure …
Run Code Online (Sandbox Code Playgroud)

csv evaluation haskell strict

3
推荐指数
1
解决办法
219
查看次数

标签 统计

csv ×1

evaluation ×1

haskell ×1

strict ×1