【问题标题】:Could not import module frege.system.Directory (java.lang.ClassNotFoundException: frege.system.Directory)无法导入模块 frege.system.Directory (java.lang.ClassNotFoundException: frege.system.Directory)
【发布时间】:2016-02-29 21:36:35
【问题描述】:

我试图在我的 Frege 程序(在 Eclipse 中)中导入 System.Directory,以便使用 getDirectoryContent 等函数,它给我写了这个错误: 无法导入模块 frege.system.Directory (java.lang.ClassNotFoundException: frege.system.Directory)

我该怎么办?

【问题讨论】:

    标签: frege


    【解决方案1】:

    这是因为模块 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 实现支持的模块。

    OP 评论更新

    这是一个简单的 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
    

    【讨论】:

    • 谢谢!但是如果我想要给定目录路径中所有文件的列表,我该如何处理frege.java.IO?我看到列表函数的定义是:list ∷ MutableIO File → IO (Maybe (ArrayOf RealWorld String))。我想做的是发送一个String并获取一个列表...我不明白该函数获取一个File并返回一个IO是什么意思。另外,我尝试使用 Java.IO 的功能来查看它是否有效,我写了“Import Java.IO”并复制了链接中的示例:createTempFile“abc”“.suffix”,我得到一个错误:can' t 解析createTempFile,你的意思是writeFile 吗?
    • @E.F 你只是忽略了createTempFileFIle 命名空间中。
    猜你喜欢
    • 2012-11-06
    • 2017-11-11
    • 2021-07-27
    • 2019-06-13
    • 2020-12-15
    • 2020-08-28
    • 2015-10-04
    • 2021-06-06
    相关资源
    最近更新 更多