相关疑难解决方法(0)

Haskell中有一些目录漫游器吗?

在Haskell中是否有一些递归目录walker所以我可以编写类似的东西

listing <- walkDir "/tmp"
Run Code Online (Sandbox Code Playgroud)

我不想写我自己的.我可以从cabal安装一些依赖,但我希望它是跨平台的(至少Linux和Windows).

io haskell directory-traversal

17
推荐指数
3
解决办法
2816
查看次数

在Haskell中流式传输目录的递归下降

我正在尝试使用Haskell进行目录结构的递归下降.我想只根据需要检索子目录和文件(懒惰).

我编写了以下代码,但是当我运行它时,跟踪显示在第一个文件之前访问了所有目录:

module Main where

import Control.Monad ( forM, forM_, liftM )
import Debug.Trace ( trace )
import System.Directory ( doesDirectoryExist, getDirectoryContents )
import System.Environment ( getArgs )
import System.FilePath ( (</>) )

-- From Real World Haskell, p. 214
getRecursiveContents :: FilePath -> IO [FilePath]
getRecursiveContents topPath = do
  names <- getDirectoryContents topPath
  let
    properNames =
      filter (`notElem` [".", ".."]) $
      trace ("Processing " ++ topPath) names
  paths <- forM properNames $ \name -> do
    let path = topPath …
Run Code Online (Sandbox Code Playgroud)

haskell directory-structure lazy-evaluation

11
推荐指数
2
解决办法
1938
查看次数