Ticket #2 (new enhancement)

Opened 8 years ago

Last modified 7 years ago

Support Complete / Incomplete distinction instead of Abs/Rel

Reported by: benmos Owned by: somebody
Priority: major Milestone:
Component: component1 Version:
Keywords: Cc:


Wren Ng Thornton (libraries list 16/Nov). ---

Having done a lot of system administration and metaprogramming of system administration, I can certainly say that making the relative/absolute distinction is helpful for tracking down bugs. From the same set of experience I'd say that Duncan's incomplete/complete distinction would be even more helpful.

With a lot of sysadmin metaprogramming (which includes package installers) what people are really working on is grafting different trees together. It's important to distinguish which paths/trees are being created and don't yet refer to an actual or potential file on the disk, from those paths/trees which refer to actual/potential files on the disk.

To think about why this distinction is helpful, consider where all we may want to attach the paths/trees we're creating. The two obvious places are / and . but there are other options too. Most programs support some notion of a $PATH variable or allow flags to specify the target directory for reading or writing. With the complete/incomplete distinction we distinguish names which aren't yet grounded from names that refer to files, regardless of where they're mounted. With the relative/absolute distinction we don't know when a path is finished being constructed, and we also have no real vocabulary for expressing paths relative from some point other than the current directory.

Most sysadmins don't seem to realize they're doing tree grafting when they mess with this stuff, so I can see why it might seem foreign, but viewing it that way really does help clean code up and find bugs. Tree grafting also forms a monad, which could be helpful for some folks.

Change History

Changed 8 years ago by benmos

See also Duncan Coutts' coments:

So in the similar design I was working on, instead of distinguishing relative and absolute, I distinguish incomplete and complete. I initially started with the relative/absolute distinction and moved onto this one. It'd be interesting to see which is most useful in practise.

What I mean by complete is a path referring to an actual file/dir that you could pass to a system call. This means they are anchored to some point the system knows about, such a "." the current directory or "/" or "C:\".

Then an incomplete path is one that is not anchored. Incomplete paths become complete by </> them to a existing complete one (including the current dir).

So the difference between this complete/incomplete notion and relative/absolute is for paths that are relative to the current directory.

You would say "Main.hs" :: RelFile?


readFile :: AbsRelClass? ar => FilePath? ar -> IO String

and so readFile "Main.hs" is ok, and reads the file "./Main.hs" in the current directory.

I would probably say, "Main.hs" :: IncompleteFilePath?

(though I think I used somewhat shorter type names than that!)


readFile :: CompleteFilePath? -> IO String

and thus readFile "Main.hs" is not well typed, instead it would be:

readFile (currentDir </> "Main.hs")

because that gives us a complete path, and if we want that to be rooted at the processes' current directory, then we do so explicitly.

My intuition with file paths in Cabal, is that this distinction would catch more bugs. Ideally cabal's building code would be independent of the current directory, but the fact that relative paths get automagically completed to being relative to the current directory means that it's very easy to break this property. The type distinction would enforce it, and you could see explicitly where paths are deliberately completed relative to the current directory (or some other root).

On the other hand it doesn't quite align with people's notion of relative paths so people might hate it :-).

There are various other distinctions one could try to make, the question becomes which type distinctions are useful and when does it just become too much. For example one could distinguish file names (with no directory part), or pure roots with no directory part (eg ".", "/", "C: \", "//server/share/").


Changed 7 years ago by benmos

Could maybe use an 'Abs / Rel / Par' scheme - where 'Par' corresponds to 'Partial'.

Note: See TracTickets for help on using tickets.