【发布时间】:2016-02-29 21:36:35
【问题描述】:
我试图在我的 Frege 程序(在 Eclipse 中)中导入 System.Directory,以便使用 getDirectoryContent 等函数,它给我写了这个错误: 无法导入模块 frege.system.Directory (java.lang.ClassNotFoundException: frege.system.Directory)
我该怎么办?
【问题讨论】:
标签: frege
我试图在我的 Frege 程序(在 Eclipse 中)中导入 System.Directory,以便使用 getDirectoryContent 等函数,它给我写了这个错误: 无法导入模块 frege.system.Directory (java.lang.ClassNotFoundException: frege.system.Directory)
我该怎么办?
【问题讨论】:
标签: frege
这是因为模块 frege.system.Directory 在 Frege 中不存在。了解模块的一个好方法是在以下 URL 使用 Hoogle for Frege:http://hoogle.haskell.org:8081。如果我们在那里search for that module,我们可以看到它没有列出任何模块,相反,如果你搜索frege.data.List,我们会在result 中看到模块。
现在对于您需要的功能,例如getDirectoryContent,如果您查看frege.system.Directory 的搜索结果,第一个结果是关于进程的,第三个和第四个结果是关于 jar 和 zip 文件的。如果您单击第二个结果,它将打开模块frege.java.IO,您可以看到一些可能对您有用的相关功能(例如list)。但是,您尝试查找的 Haskell 模块尚未移植到 Frege,但它当然应该可以移植由本机 Java 实现支持的模块。
这是一个简单的 sn-p 来返回给定目录下的文件:
ls :: String -> IO [String]
ls dir = do
contents <- File.new dir >>= _.list
maybe (return []) (JArray.fold (flip (:)) []) contents
关于createTempFile,以下对我有用:
frege> File.createTempFile "test.txt"
String -> STMutable RealWorld File
【讨论】:
createTempFile,你的意思是writeFile 吗?
createTempFile 在FIle 命名空间中。