[Haskell] System.FilePath survey
droundy at abridgegame.org
Mon Feb 6 08:12:41 EST 2006
On Mon, Feb 06, 2006 at 12:08:12PM +0300, Bulat Ziganshin wrote:
> Hello Einar,
> Saturday, February 04, 2006, 12:00:18 AM, you wrote:
> >> KA> * Do you think that we have to use unboxed arrays of Word8/Word16
> >> KA> for file path?
> well, if FilePath should be ADT, then:
> 1) all operations that returns filenames (getFileContents, anything
> more?) should return this ADT instead
You mean getDirectoryContents?
getCurrentDirectory, getHomeDirectory, getTemporaryDirectory, etc.
All sorts of Cabal stuff.
Some of these could just return String. Others could return the ADT...
Actually couldn't they all be made polymorphic?
getDirectoryContents :: FilePath p => IO p
class FilePath p where
fromADT :: ADT -> p
toADT :: p -> ADT
(where I have declined naming the ADT)
> 2) this ADT should support conversion to/from String (for interaction
> with users) and to/from [Word8] (to send these values across
> storage/network). Of course, these conversions should be as exact and
> revertible as possible, i think that at least we can make guarantee
> for ascii chars
Probably we'd also want a withCString equivalent that works with the ADT,
for use when working with the FFI. True, you could do the conversion via
[Word8], but that's ugly (and potentially inefficient, depending how the
ADT is stored internally).
> 3) all operations that receives filenames should accept a _class_
> which includes String/[Word8]/this ADT
That would be nice, but I suspect not strictly necessary.
> of course, this means incompatible changes in the APIs, so it's better
> to introduce new fucntions that returns ADT/accepts class with a new
I don't know. I'd lean towards not introducing new function names. The
point of accepting the class would be that existing code would continue to
work. The only code that would be broken would be code that uses
getFileContents, which is a sufficiently small minority of code that I
would say just let it break. You'd leave the Haskell 98 Directory module
returning String, but I'd vote to make System.Directory.
More information about the Libraries