[Haskell-cafe] Encoding-aware System.Directory functions

Max Bolingbroke batterseapower at hotmail.com
Wed Mar 30 12:37:55 CEST 2011


On 30 March 2011 10:20, Tako Schotanus <tako at codejive.org> wrote:
>> http://www.haskell.org/pipermail/libraries/2009-August/012493.html
>> I took from this discussion that FilePath really should be a pair of the
>> actual filename ByteString, and the printable String (decoded from the
>> ByteString, with encoding specified by the user's locale). The conversion
>> from ByteString to String (and vice versa) is not guaranteed to be lossless,
>> so you need to remember both.

My understanding is that the ByteString is the one "source of truth"
about what the file is called, and you can derive the String from that
by assuming some encoding, which is what I proposed in my earlier
message. I guess that as an optimisation you could cache the String
decoded with a particular encoding as well, but to my mind it's not
obviously worth it.

> I'm not sure that  I agree with that. Why does it have to be loss-less?
> The problem, more likely, is the fact that FilePath is just a simple string.
> Maybe we should go the way of Java where cross-platform file access is based
> upon a File (or the new Path) type?

An opaque Path type has been discussed before and would indeed help a
lot, but it would break backwards compatibility in a fairly major way.
It might be worth it, though.

Max



More information about the Haskell-Cafe mailing list