solvuu / phat

Strongly typed file path and file system operations.
ISC License
27 stars 4 forks source link

Auto-referencing links #12

Closed pveber closed 8 years ago

pveber commented 8 years ago

A item of the form Link (n, Item (File n)) or Link (n, Cons (Dir n, ...)) or Link (n, Link (n, ...)) should be detected and forbidden: this is a broken link and is better represented by Broken_link (n, [ n ]). In addition that makes the implementation of some cycle-safe function much easier (reify, for instance).

pveber commented 8 years ago

An additional comment is that Phat_path should maybe become private.

agarwal commented 8 years ago

this is a broken link

Our definition of "broken link" is a link whose target doesn't exist. Now we have to decide what "doesn't exist" means. Does it mean:

i. the path doesn't exist at all, or ii. it doesn't exist as the type of file object specified

If (i), then these examples are not necessarily broken links. If (ii), then the first two are broken: Link to a File, and Link to a Dir. The Link to Link is not broken, just cyclic.

I'm unclear what specific problem there is. When traversing a directory tree (whether for fold or reify), you already have to look for cycles and paths that are broken for any number of reasons. Does a self-reference pose any unique problem?

pveber commented 8 years ago

What's specific here is that you don't even need to look at a filesystem to see that the link is broken: it is broken because of never-ending resolution. So I think something specific should be done for them, which is indeed not sufficient when you want to implement fold of reify, alas...

agarwal commented 8 years ago

So we've got two kinds of broken paths:

agarwal commented 8 years ago

Closing this issue as it has become a duplicate of #4.

pveber commented 8 years ago

For the sake of completeness, the second case referred to by @agarwal (cyclic ocaml values) is made impossible by 8f1749f.

agarwal commented 8 years ago

Summary of our discussion on 8f1749f1db2ab48685cd83e612ffed5afff81f93, which makes Item a private type.

Pros:

Con:

So the pros and cons are both minor. For now, let's stick with the private type to err on the side of providing extra safety.

agarwal commented 8 years ago

For the record, we reverted this in 55772965fe272562bbd68e980674dbfb8214e635. So now we again allow cyclic OCaml values and assume users won't provide such values.