[Haskell-cafe] How to determine if a FilePath is a directory name or regular file?

Deniz Dogan deniz.a.m.dogan at gmail.com
Mon Jun 22 08:09:56 EDT 2009


2009/6/22 Duncan Coutts <duncan.coutts at worc.ox.ac.uk>:
> On Mon, 2009-06-22 at 08:53 +0200, Deniz Dogan wrote:
>> 2009/6/22 Colin Paul Adams <colin at colina.demon.co.uk>:
>> >>>>>> "Judah" == Judah Jacobson <judah.jacobson at gmail.com> writes:
>> >
>> >    Judah> On Sun, Jun 21, 2009 at 11:12 PM, Colin Paul
>> >    Judah> Adams<colin at colina.demon.co.uk> wrote:
>> >    >> I've been hoogling like bad to try to determine if a function
>> >    >> like this exists.
>> >    >>
>> >    >> getDirectoryContents returns sub-directories as well as file
>> >    >> names. I want only the latter, so I'm looking for a suitable
>> >    >> filter.
>> >
>> >    Judah> Use System.Directory.doesDirectoryExist/doesFileExist.
>> >
>> > Thanks.
>> >
>> > it seems it's time i went to the optician again.
>>
>> I'm not surprised that anyone would make the mistake. I think that the
>> two functions should be named "isDirectory" and "isFile", but it seems
>> that "isDirectory" was already taken by another function in
>> System.Directory, which is quite unfortunate. "does" goes against the
>> intuition one gets from pretty much everything else in Haskell, where
>> "is" seems to be the convention. In fact, Hoogle only knows about
>> three functions which start with "does".
>
> One explanation is that isBlah asks "is this thing a blah", but we're
> not asking that because there is an indirection via the filepath. We're
> asking "does this filepath refer to a directory" not "is this filename a
> directory". The latter could be a function:
>
> isDirectory :: FileInfo -> Bool
>
> along with a hypothetical
>
> getFileInfo :: FilePath -> IO FileInfo
>
> Duncan
>
>

I think see what you mean, but I find the argument more of an excuse
to the poor naming than a solid argument for it. Following the
convention and intuition that most users have should be more important
than making the (sometimes unnecessary) distinction between a
directory and the path to it.

-- 
Deniz Dogan


More information about the Haskell-Cafe mailing list