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

David Roundy droundy at darcs.net
Thu Jul 20 07:23:31 EDT 2006

On Wed, Jul 19, 2006 at 03:16:48AM +0100, Neil Mitchell wrote:
> >I tried to export a minimal set of operations that seem to me sufficient
> >for everything not very platform-specific (though I am interested in
> >counterexamples):
> Anything to do with file extensions? Its also important (I feel) for
> people to have easy access to common operations, but I guess that is a
> design decision.

Personally, I don't care for the idea of doing anything with file
extensions.  Handling file extensions is a bit tricky, in the sense
that it's ambiguous what the application actually wants, and so
(unlike the other parts of the FilePath library, which reflect how the
OS sees a FilePath) there's no real solution.  e.g. is foo.ps.gz a .ps
file, or just a .gz file or a .ps.gz file? I can open it with gv (a
postscript viewer), but can't open any other .gz file with gv.

In general, I feel that file extensions are most often useless, and a
better approach to almost any use of them would be something like
libmagic to identify files, or access to mailcap, for instance.
Perhaps as part of a mime-support package, which would have something

identifyMimeType :: FilePath -> IO String -- or ADT for mime types
getMimeHandler :: FilePath -> IO (IO FilePath)
-- te above returns a wrapped function that calls the mime handler for
-- specified file

Note that the latter is actually the more portable, as it wouldn't
even need to use MIME as an intermediate, but could look up the
handler based on file extension on platforms where that's
David Roundy

More information about the Haskell-Cafe mailing list