filepath icon indicating copy to clipboard operation
filepath copied to clipboard

Lexigraphic ordering

Open amigalemming opened this issue 1 year ago • 5 comments

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.

amigalemming avatar Feb 04 '24 09:02 amigalemming

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

hasufell avatar Feb 04 '24 09:02 hasufell

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)

amigalemming avatar Feb 04 '24 09:02 amigalemming

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 avatar Feb 04 '24 09:02 hasufell

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.

hasufell avatar Feb 04 '24 10:02 hasufell

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'.

amigalemming avatar Feb 04 '24 10:02 amigalemming