[Haskell-cafe] Re: File path programme

John Meacham john at repetae.net
Tue Feb 1 18:50:49 EST 2005


I have not been following this thread too closely, but I have looked at
the various proposed implementations floating around and have a few
comments.

I noticed some have #ifdefs for platforms, which seems not very useful.
I write not just cross-platform, but cross platform at the same time
programs. i.e. a linux program which might be controlling slaves running
on windows or linux, meaning it will have to deal with paths from either
operating system in a common way. We should make sure all functionality
is available on all systems as much as is feasable. Another common use
is a program running under cygwin, where you generally want to let the
user work with unix or windows style paths. 

We need to support paths as black boxes, what is returned from directory
routines should be able to be passed back to system routines without
modification or canonicalization. This will allow people to write
file-chooser type apps, so even if the user visible display name of a
file has been changed by charset conversion/whatnot, we can still pass
the black box gotten out of the directory listing back to an open call
and be assured of getting the right file. 

I don't think this is a good use of typeclasses mainly because I don't
think we should use different types for different platforms. I would
like a single abstract Path type which can represent paths from any
platform or an encapsulated black box from the system.

I liked the root-relative formulaton someone mentioned.


data FilePath = Path Root [Relative]

data Root = WindowsDrive Char 
        | UnixRoot 
        | CurrentDir 
        | RootBB BlackBox

data Relative = Dot | DotDot | Sub String | SubBB BlackBox

type BlackBox = UArray Int Word8

note that black boxes can be used as path components as well as the
entire path. Examples of where these would be used would be getting the
current directory would return an opaque black box representing the
whole path, while a directory listing would return relative black boxen.
Or imagine implementing cp -r, you'd want to create the same file names in a
different directory.

just some comments... sorry for the hit-n-run.

        John

-- 
John Meacham - ⑆repetae.net⑆john⑈ 


More information about the Haskell-Cafe mailing list