haskell / filepath

Haskell FilePath core library
BSD 3-Clause "New" or "Revised" License
66 stars 33 forks source link

Lexigraphic ordering #225

Open amigalemming opened 5 months ago

amigalemming commented 5 months ago

Additionally to equalFilePath we also need compareFilePath for sorting the contents of a directory and for Posix we need a case-sensitive and a case-insensitive version for Linux and MacOS, respectively.

hasufell commented 5 months ago

Please be more specific. What exactly is the type signature of compareFilePath? What is the implementation?

amigalemming commented 5 months ago

I think it should be:

compareFilePath :: OsPath -> OsPath -> Ordering

It should at least be compatible with equalFilePath, that is:

property $ \x y -> equalFilePath x y == (compareFilePath x y = EQ)
hasufell commented 5 months ago

for sorting the contents of a directory

Why not just use compare (which is bytestring comparison)? That will sort it. Afterwards you can still apply equalFilePath if you need more precise distinction.

hasufell commented 5 months ago

Afterwards you can still apply equalFilePath if you need more precise distinction.

In fact, given your use case of sorting directory contents, this is entirely obsolete, since you cannot have the same file twice. So compare is enough.

amigalemming commented 5 months ago

On Sun, 4 Feb 2024, Julian Ospald wrote:

  for sorting the contents of a directory

Why not just use compare (which is bytestring comparison)? That will sort it. Afterwards you can still apply equalFilePath if you need more precise distinction.

I see there is more specification needed. I think about something like "compare (map toLower x) (map toLower y)", such that 'a' comes before 'B', whereas in case-sensitive ordering 'a' comes after 'B'. First ordering case-sensitive then filtering case-insensitive would not work in case of 'B', 'a', 'b'.