[Haskell-cafe] Re: ANN: System.FilePath 0.9

Neil Mitchell ndmitchell at gmail.com
Wed Jul 26 13:47:50 EDT 2006


> Perhaps instead:
>    directoryOf :: FilePath -> String
>    filenameOf  :: FilePath -> String
>    extensionOf :: FilePath -> String
>    basenaneOf  :: FilePath -> String
>    replaceFilename  = joinFilePath . directoryOf
>    replaceDirectory = flip joinFilePath . filenameOf

Trying to design a consistent naming system, it helps if we all agree
on what the various parts of a filepath are called, this is my draft
of that:


With a better name for basename, if anyone can think of one.

Once we have that, how about

takeElement :: FilePath -> String
dropElement :: FilePath -> String
replaceElement :: FilePath -> String -> FilePath
addElement :: FilePath -> String -> FilePath
splitElement :: FilePath -> (String, String)
joinElement :: String -> String -> FilePath

With the restriction that not all of these are provided. Some don't
make sense (splitBaseName, dropBaseName), some are implemented via
combine (addFileName, joinFileName), some are redundant (addExtensions
== addExtension)

I'm also debating whether split/join should be exported, since they
are less likely to be used and can easily be written as a take/drop
pair. And of course, a bigger interface is harder to understand.

Opinions on this? It's easier to tweak a specification than the actual code :)



More information about the Haskell-Cafe mailing list