-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move ‘dirname’ and ‘parent’ into ‘MonadThrow’ #90
Conversation
8bd18e8
to
4b2b0ef
Compare
@NorfairKing Can you adjust the validity tests? |
Yes! Dirname doesn't have validity tests yet though, so I'll add those. |
@mrkkrp Can you update the docs as well? |
And could you also check the property for 'parent' because it doesn't seem to hold:
|
|
Does everyone agree with the decision about |
Sounds great! Feel free to add the tests as well then . |
src/Path.hs
Outdated
Path (normalizeDir (FilePath.takeDirectory (FilePath.dropTrailingPathSeparator fp))) | ||
parent :: MonadThrow m => Path Abs t -> m (Path Abs Dir) | ||
parent = parseAbsDir | ||
. normalizeDir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect that this line is redundant. Would you mind removing it and checking if everything still seems to work as expected?
I do.
That constructor doesn't really sound like a "parse exception" but Can you add tests for when |
Oh, and how about adding BTW in the changelog you can substitute |
AppVeyor fails with a weird message (doesn't know what |
Seems like a new AppVeyor issue – can you apply the workaround here? |
test/Posix.hs
Outdated
it "parent (parent \"\") == \"\"" | ||
((parent $(mkAbsDir "/") >>= parent) `shouldReturn` | ||
$(mkAbsDir "/")) | ||
it "cannot take the parent of the root directory" $ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should instead use shouldThrow
here and check that it throws the correct thing, not discard the info checking against Nothing
. I'll push a fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructors of the exception are not supported, are they?
If they are, then I missed that :)
It looks like we don't export constructors of |
Yes please. |
244772c
to
19ca02f
Compare
@sjakobi Good to go now, what do you think? |
Oh, yes they are. My bad.
parent $(mkAbsDir "/") `shouldBe` Right (Couldn'tTakeParent "/") |
Otherwise, LGTM |
Please don't add your answers in my post by editing it, it's confusing. And this parent $(mkAbsDir "/") `shouldBe` Right (Couldn'tTakeParent "/") is not going to work: (~) * e SomeException => MonadThrow (Either e) So it will be |
Oh dear! I didn't know I was doing that. I'm so sorry!
Oh, right. Carry on! LGTM from me :) |
e676f1e
to
54a6587
Compare
I'm sorry that this comes so late, but I've got some doubts about our (type) design here:
|
+1 |
@mrkkrp @sjakobi PR #35 which was reviewed by @chrisdone long ago but was never merged (I guess he got busy), fixes the parent related part in this PR. There may be a few things from the changes in that PR that may be worth taking or maybe you can merge that one first. That PR changed the exception naming as well, you may want to take a look at the review comments in that one. I agree |
That just doesn't fit with my intuition of what a "directory name" is. I really think that |
I will say don't add them (i.e. fileParent and dirParent) now, adding later is always easier, if we really want to, but removing later is painful. |
If we don't split
You never "don't care" whether a path is a file or a dir, you can only "not know" and write a function that works for both. If you use
I disagree entirely. The opposite is true, in my opinion. The cognitive overhead of not splitting case parent myFile of
Nothing -> error "cannot happen anyway"
Just parentOfMyFile -> pure $ myFunc parentOfMyFile Types should not lie. |
If we move fileParent :: Path Abs File -> Path Abs Dir
fileParent = fromJust . parent But again if you need it so badly you can do it yourself in your code. And yes |
I'm okay with that. The difference is who maintains it. As long as |
Are we ready to merge this then? |
I think we're close. @sjakobi mentioned that he suspects that |
With this fix we are moving towards an unnecessarily complex API. Let me explain. Just like the POSIX standard path API, our path API could be as simple as just two pure functions i.e.
This is succinct and simple API, look how the signatures of all three fit in. And, we have the following simple laws too:
With MonadThrow instances and splitting the API we are moving away from this simpler picture and towards a more ad-hoc API. To be able to keep this simpler picture I propose the following semantics for the special root case, assuming we also have the change to represent the empty path or ".":
With these semantics all the laws are elegantly satisfied and everything is still pure. We already have the first of these, the only change we need is the second one. We discussed this earlier above and dismissed as non-intuitive, but it makes sense and fulfills the laws. If you think about it, the basename of "/" is in fact an empty name and that is what we represent with "." (it is I request all the maintainers to take another look at this and strive to keep the API as simple as possible, since this is a fundamental library for path manipulations. I use and care about this library, so I tried to make a bit more effort to convince you guys. |
BTW, I have a change that combines |
I'm sort-of okay with |
What is wrong with Seems perfectly reasonable to me. If you type |
I can get my head around it, as long as
As for the typeclass: I think this will create more problems than it solves. |
Such as? I've never head of a typeclass creating problems. |
|
Making We are (rather incorrectly) calling the POSIX If we use the same
|
👍
Should we rename it? (let's make that a seperate issue, if so)
I disagree, it still needs to be consistent. Every parent is a prefix. By the way, nothing says that we have to make the API look like the shell equivalent. What do you suggest then, concretely and stepwise? |
If that is desired we can fix
Yes, of course. But as long as there is no other serious conflict it is always helpful to reuse an established and popular API. One, that API has been through the test of time, reviewed and used by countless people. Two, it helps people who have gotten used to it, for example initially I always made the mistake of using
To Fix #18:
Nice to have's, issues to be raised/discussed:
|
I'm okay with this plan, but I want to hear others' opinion. (I thought @chrisdone didn't like this approach.) |
I'm ok with keeping I'm still rather -1 on |
👍
I'm wondering if it would be better to offer both API's? |
I like that idea. It allows users to decide which behavior is desirable. |
One way to think about it is It does not sound intuitive because the representation "." is overloaded with two meanings i.e. the RelRoot as well as the identity of concatenation for relative paths. Conceptually if we write it like this, then it may look more intuitive:
We can conclusively establish that it is a design flaw if we can find one practical problem that it causes and is against the accepted uses of "." and "/". |
Closed in favor of #34. |
Close #18.