You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Well they have differences that we can statically enforce since sub libraries must have a name (which currently is not enforced) and main libraries cannot have a name (identically not enforced).
So joining them in the same list is going against their current structural differences, in my opinion.
Now of course, maybe that's not what was intended and we allow main libraries to have a name and give the Library type a simple isMain boolean, but in the current situation my proposal seems like a better fit.
PS : Also, having a list like you said enable yet another structural violation that is main libraries must be unique, if they exist.
PS2: About the Map data structure it solves the unicity and naming requirements above, but it means we pay extra for acessing the main library which I don't find particularly good since I expect main libraries to be accessed very often... Also It allows for different library names in the keys and in the value which is arguably weird as a structure (not that it's a real risk, just that it's a bit hard to grasp on first sight, I think).
More type safety is nice, and I welcome any improvement in that direction, but the increase in complexity is nonzero and we fist have to ask ourselves why we need it.
In this case, we are trying to enforce the difference between main (or unnamed) libraries and "sublibraries" (or named libraries), but since both can be public now is there an actual difference in how we use them? There is only one that I can think of: the main unnamed library defaults to visibility: public, while named libraries default to visibility: private. That difference is already handled where we do the defaulting, by looking at the library name, and I'm not sure it could be made safer through types.
Then, I expect the rest of the code that uses library and subLibraries to be like
doThing library
doThing <$> subLibraries
with no special treatment for library at all. If that's the case, I think merging the two fields is perfectly fine.
If there are other differences, it could even be a bug: anywhere a main/named library can be used, I expect to be able to use a sub/unnamed library!
The only way to find out is to actually try making the change.
Now of course, maybe that's not what was intended and we allow main libraries to have a name and give the Library type a simple isMain boolean
My point is that we don't even need that. We can just look at the name.
Also, having a list like you said enable yet another structural violation that is main libraries must be unique, if they exist.
subLibraries already violates the constraint of uniqueness of library names.
About the Map data structure it solves the unicity and naming requirements above, but it means we pay extra for acessing the main library which I don't find particularly good since I expect main libraries to be accessed very often
That's a good point but we'd have to prove that with benchmarks.
Tbh I think a list is fine. The map doesn't really solve the duplication problem at the type level because of the duplication you point out, and I'd expect its size to be (typically) small enough that a list would actually be faster than a map and comparable to the current situation.
My point is that we don't even need that. We can just look at the name.
And my point is we should not even need to look at the name since the cabal file tell us by construction which is a main and which is a sub.
subLibraries already violates the constraint of uniqueness of library names.
I didn't mention sub library names uniqueness here, I mentioned the fact that you can't have unnamed sublibraries. Maybe I'm missing something ? If not my point stands.
That's a good point but we'd have to prove that with benchmarks.
Tbh I think a list is fine. The map doesn't really solve the duplication problem at the type level because of the duplication you point out, and I'd expect its size to be (typically) small enough that a list would actually be faster than a map and comparable to the current situation.
Ok I understand your position and everything, but really I'm not interested in merging the two distinct data structures (made distinct by cabal in its very file design) as identical in the PackageDescription, I feel this is would not be an improvement at all.
Besides I don't see how this is a simplification, if almost all operations are targeting both, we can simply create a function merging the two in 2 seconds and use it everywhere it make sense (if that's no already the case), while retaining the potential for easy differentiation if needed :
I mean, again, maybe this distinction is in itself bad and the very cabal file structure should be revisioned to merge their layout/distinctions, but for now, it's just merging actual differences we can statically enforce. In the stack codebase there are maybe a hundred places where we specifically target the main library. Maybe that's just because stack is old and clunky I don't know, but having to run a find search in a list with a boolean everywhere we used to simply apply a function does not seem like progress to me.
And my point is we should not even need to look at the name since the cabal file tell us by construction which is a main and which is a sub.
What construction? In my comment I've been calling them "named" and "unnamed" exactly because with the multiple public libraries feature there isn't a meaningful distinction anymore. They differ in name, just like library foo and library bar do, and in default(!) visibility.
I didn't mention sub library names uniqueness here
No, but I argue that library name uniqueness is a superset of main library uniqueness.
Ok I understand your position and everything, but really I'm not interested in merging the two distinct data structures (made distinct by cabal in its very file design) as identical in the PackageDescription, I feel this is would not be an improvement at all.
[...]
I mean, again, maybe this distinction is in itself bad and the very cabal file structure should be revisioned to merge their layout/distinctions
There is no distinction between the two structures. Both are Library, and both are described in the same (admittedly outdated) doc section. The layout is the same.
I do argue that the distinction of fields is bad, but changing that won't touch the .cabal file format.
Besides I don't see how this is a simplification, if almost all operations are targeting both, we can simply create a function merging the two in 2 seconds and use it everywhere it make sense (if that's no already the case), while retaining the potential for easy differentiation if needed
With the current design, I think that differentiation shouldn't be needed at all. It'd be like having a libraryNamedFoo field that's only for libraries named "foo".
There is a difference, but that's only in how we produce the library, specifically in how we set the default visibility. It shouldn't make a difference at all when processing a library externally (that's where a GADT would be most useful), because you'd have to look up the visibility anyway.
(by the way, the function you describe is Distribution/Types/PackageDescription.allLibraries)
In the stack codebase there are maybe a hundred places where we specifically target the main library. Maybe that's just because stack is old and clunky I don't know, but having to run a find search in a list with a boolean everywhere we used to simply apply a function does not seem like progress to me.
Let's not be antagonistic, it just has yet to catch up with the latest Cabal features. Here's how the cabal format evolved:
One library per package
Multiple sublibraries for private use, distinct from the main, public library <- stack is here
With visibility, the concepts of "main library" and "sublibrary" are unified <- Cabal and cabal-install are here
In (2) it makes sense to have two different fields, in (3) not so much in my opinion. Of course breaking backward compatibility is not pleasant, but the feature has been there for a while, and I think a cleanup is worthwhile. You write yourself that there's an effort to "move stack closer to cabal design".
So I'll leave it to this then. Have a nice day.
My comment wasn't meant to discourage you, quite the opposite. I'm interested in cleaning up those fields.
If you can show an example of code that can be made safer with the change you propose, and that would be worsened by dropping the distinction, by all means let's do it.
@fgaz, I really appreciate the time you take to fill in the gap between your knowledge and my understanding.
I do argue that the distinction of fields is bad, but changing that won't touch the .cabal file format.
And I argue that the PackageDescription should be a strict mirror of the acceptable structure in the cabal file. Admittedly, It's already not the case now (as per your comment on uniqueness), but merging libraries into a list is strictly worse from this perspective. And honestly, this is not even a matter of type safety, it's rather a materialization of some constraints and assumptions that are widespread in the codebase.
The Map is the only interesting option following this principle (and would be interesting for all component lists indeed), interestingly enough, there is a lookupComponent function but it doesn't seem to be used much.
If you can show an example of code that can be made safer with the change you propose, and that would be worsened by dropping the distinction, by all means let's do it.
Ok sounds good, I'll look at the state of the main/sub distinction use in the codebase 👍
Activity
theobat commentedon Nov 3, 2022
It seems a bit more involved than I thought, Library type beeing used a lot, but i can propose a draft if people see the interest ?
fgaz commentedon Nov 3, 2022
Can we instead unify
libraryandsubLibrariesinto a singlelibraries :: [Library]field, or maybe even:: Map LibraryName Library?I didn't dare change it when I added the
LibraryNametype, but as far as I know the distinction isn't really needed.theobat commentedon Nov 3, 2022
Well they have differences that we can statically enforce since sub libraries must have a name (which currently is not enforced) and main libraries cannot have a name (identically not enforced).
So joining them in the same list is going against their current structural differences, in my opinion.
Now of course, maybe that's not what was intended and we allow main libraries to have a name and give the Library type a simple isMain boolean, but in the current situation my proposal seems like a better fit.
PS : Also, having a list like you said enable yet another structural violation that is main libraries must be unique, if they exist.
PS2: About the Map data structure it solves the unicity and naming requirements above, but it means we pay extra for acessing the main library which I don't find particularly good since I expect main libraries to be accessed very often... Also It allows for different library names in the keys and in the value which is arguably weird as a structure (not that it's a real risk, just that it's a bit hard to grasp on first sight, I think).
theobat commentedon Nov 11, 2022
jaror on discourse proposed an even better design with GADTs :
https://discourse.haskell.org/t/why-dont-we-narrow-type-arguments-more-frequently/5299/4
I'm still motivated to implement this but I'm waiting for some sort of validation ?
fgaz commentedon Nov 12, 2022
More type safety is nice, and I welcome any improvement in that direction, but the increase in complexity is nonzero and we fist have to ask ourselves why we need it.
In this case, we are trying to enforce the difference between main (or unnamed) libraries and "sublibraries" (or named libraries), but since both can be public now is there an actual difference in how we use them? There is only one that I can think of: the main unnamed library defaults to
visibility: public, while named libraries default tovisibility: private. That difference is already handled where we do the defaulting, by looking at the library name, and I'm not sure it could be made safer through types.Then, I expect the rest of the code that uses
libraryandsubLibrariesto be likedoThing library doThing <$> subLibrarieswith no special treatment for
libraryat all. If that's the case, I think merging the two fields is perfectly fine.If there are other differences, it could even be a bug: anywhere a main/named library can be used, I expect to be able to use a sub/unnamed library!
The only way to find out is to actually try making the change.
fgaz commentedon Nov 12, 2022
My point is that we don't even need that. We can just look at the name.
subLibrariesalready violates the constraint of uniqueness of library names.That's a good point but we'd have to prove that with benchmarks.
Tbh I think a list is fine. The map doesn't really solve the duplication problem at the type level because of the duplication you point out, and I'd expect its size to be (typically) small enough that a list would actually be faster than a map and comparable to the current situation.
theobat commentedon Nov 12, 2022
And my point is we should not even need to look at the name since the cabal file tell us by construction which is a main and which is a sub.
I didn't mention sub library names uniqueness here, I mentioned the fact that you can't have unnamed sublibraries. Maybe I'm missing something ? If not my point stands.
Ok I understand your position and everything, but really I'm not interested in merging the two distinct data structures (made distinct by cabal in its very file design) as identical in the PackageDescription, I feel this is would not be an improvement at all.
Besides I don't see how this is a simplification, if almost all operations are targeting both, we can simply create a function merging the two in 2 seconds and use it everywhere it make sense (if that's no already the case), while retaining the potential for easy differentiation if needed :
I mean, again, maybe this distinction is in itself bad and the very cabal file structure should be revisioned to merge their layout/distinctions, but for now, it's just merging actual differences we can statically enforce. In the stack codebase there are maybe a hundred places where we specifically target the main library. Maybe that's just because stack is old and clunky I don't know, but having to run a find search in a list with a boolean everywhere we used to simply apply a function does not seem like progress to me.
So I'll leave it to this then. Have a nice day.
fgaz commentedon Nov 12, 2022
What construction? In my comment I've been calling them "named" and "unnamed" exactly because with the multiple public libraries feature there isn't a meaningful distinction anymore. They differ in name, just like
library fooandlibrary bardo, and in default(!) visibility.No, but I argue that library name uniqueness is a superset of main library uniqueness.
There is no distinction between the two structures. Both are
Library, and both are described in the same (admittedly outdated) doc section. The layout is the same.I do argue that the distinction of fields is bad, but changing that won't touch the .cabal file format.
With the current design, I think that differentiation shouldn't be needed at all. It'd be like having a
libraryNamedFoofield that's only for libraries named "foo".There is a difference, but that's only in how we produce the library, specifically in how we set the default visibility. It shouldn't make a difference at all when processing a library externally (that's where a GADT would be most useful), because you'd have to look up the visibility anyway.
(by the way, the function you describe is
Distribution/Types/PackageDescription.allLibraries)Let's not be antagonistic, it just has yet to catch up with the latest
Cabalfeatures. Here's how the cabal format evolved:stackis herevisibility, the concepts of "main library" and "sublibrary" are unified <-Cabalandcabal-installare hereIn (2) it makes sense to have two different fields, in (3) not so much in my opinion. Of course breaking backward compatibility is not pleasant, but the feature has been there for a while, and I think a cleanup is worthwhile. You write yourself that there's an effort to "move stack closer to cabal design".
My comment wasn't meant to discourage you, quite the opposite. I'm interested in cleaning up those fields.
If you can show an example of code that can be made safer with the change you propose, and that would be worsened by dropping the distinction, by all means let's do it.
theobat commentedon Nov 12, 2022
@fgaz, I really appreciate the time you take to fill in the gap between your knowledge and my understanding.
And I argue that the
PackageDescriptionshould be a strict mirror of the acceptable structure in the cabal file. Admittedly, It's already not the case now (as per your comment on uniqueness), but merging libraries into a list is strictly worse from this perspective. And honestly, this is not even a matter of type safety, it's rather a materialization of some constraints and assumptions that are widespread in the codebase.The Map is the only interesting option following this principle (and would be interesting for all component lists indeed), interestingly enough, there is a lookupComponent function but it doesn't seem to be used much.
Ok sounds good, I'll look at the state of the main/sub distinction use in the codebase 👍