1

I tried to import System.Directory in my Frege program (In Eclipse) in order to use functions as getDirectoryContent, etc., and it writes me this error : Could not import module frege.system.Directory (java.lang.ClassNotFoundException: frege.system.Directory)

What do I have to do ?

E.F
  • 199
  • 1
  • 1
  • 10

1 Answers1

2

It is because the module frege.system.Directory doesn't exist in Frege. A good way to find out about a module is to use Hoogle for Frege at this URL: http://hoogle.haskell.org:8081. If we search for that module there, we can see that it doesn't list any module as opposed to, say, if you search for frege.data.List, we would see the module in the result.

Now for the functions you need like getDirectoryContent, if you look at the search result for frege.system.Directory, the first result is about processes and the third and fourth results are about jars and zip files. If you click on the second result, it would open the module frege.java.IO and you can see some relevant functions that might be useful for you (list for example). However the Haskell module you are trying to find is not yet ported to Frege but it should, of course, be possible to port that module backed by native Java implementations.

Update for OP's comment

Here is a simple snippet to return the files under a given directory:

ls :: String -> IO [String]
ls dir = do
   contents <- File.new dir >>= _.list
   maybe (return []) (JArray.fold (flip (:)) []) contents

Regarding createTempFile, the following works for me:

frege> File.createTempFile "test.txt"
String -> STMutable RealWorld File
Community
  • 1
  • 1
Marimuthu Madasamy
  • 13,126
  • 4
  • 30
  • 52
  • Thanks!But if I want the list of all files in a given directory path,how can I do with frege.java.IO?I see that the definition of the list function is : list ∷ MutableIO File → IO (Maybe (ArrayOf RealWorld String)).What I want to do is to send a String and get a list...I don't understand what does it mean that the function gets a File and returns an IO. Also, I tried to use the functions of Java.IO to see if it works, I wrote "Import Java.IO" and copied the example in the link : createTempFile "abc" ".suffix" and I get an error: can't resolve `createTempFile`, did you mean `writeFile` perhaps? – E.F Mar 01 '16 at 21:15
  • @E.F you simply overlooked that `createTempFile` is in the `FIle` namespace. – Ingo Mar 09 '16 at 20:21