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
I'm currently working on implementing (and writing tests for) a cabal saved-config update command (which read's the user's ~/.cabal/config and the writes it back with comments from the current version).
During this exercise, I found some odd issues around using mappend on the SavedConfig structure. In particular where elements of that structure are lists, eg extra-prog-path, remote-repo and build-summary some opertations with mappend resulted in duplicate entries in the above variables.
On IRC @dcoutts said that all three of these do in fact need to be lists, but for all of them they should be de-duplicated lists.
My proposal is the replace the list for the above three config elements with a NubList type, a list where every element in the list is unique to the list but which also maintains the original list ortder. I would then define a Monoid instance for NubList (the properties of identity, associativity, and closure are all satisifed)
so that mappend-ing SavedConfig will then work in a sensible manner. Obviously I would be adding QuickCheck properties for the Monoid NubList instance.
@23Skidoo That's interesting. One thing I notice is that what you have there requires the Ord typeclass so that the list can be sorted. For things like extra-prog-path the original ordering may be important and should be maintained which is not possible when using your ordNubRight function.
I actualy have my fixes for this very close to working. I just need to add some more tests before I push it to github so we can discuss it futher.
@erikdordNub does preserve the original ordering and is equivalent to nub. The reason I also added a right-biased variant is that with program options you want ["-XNoFoo", "-XFoo"] mappend ["-XNoFoo"] to result in ["-XFoo", "-XNoFoo"]. Not sure if that's the case with paths, but you can of course use the left-biased ordNub.
Maybe we could define both left and right biased versions of NubList, NubListL and NubListR.
The nice thing about using a type rather than just defining functions to do this is that the types can enforce the invariants while maintaining the ability to just use mappend.
The nice thing about using a type rather than just defining functions to do this is that the types can enforce the invariants while maintaining the ability to just use mappend.
I'm +0 on using types for this. Usually we're not mappending NubLists themselves, but records that include them as members, for which one has to write boilerplate Monoid instances anyway.
The fact that the records are mappened-ed is exactly why you need to components inside the record to do the right thing by default. That is why you want to encode the right bechaviour in the types.
@23Skidoo in lieu of a much more time intensive and possibly harder to understand data structure that probably wouldn't be worth it, NubList is the right way to do this in my opinion. They're typically small lists and fixing the correctness problem in this manner is more "by construction" than the code it replaced.
The problem is that the tests I wrote for the feature I added were failing because of the existing behaviour mappend on the SavedConfig type. The NubList code therefore needs to be applied before adding the new features.
I've lost count of how many times I rebased this set of commits, but I will do it once more.
Activity
23Skidoo commentedon Oct 14, 2014
See also #2111.
erikd commentedon Oct 14, 2014
@23Skidoo That's interesting. One thing I notice is that what you have there requires the
Ordtypeclass so that the list can be sorted. For things likeextra-prog-paththe original ordering may be important and should be maintained which is not possible when using yourordNubRightfunction.I actualy have my fixes for this very close to working. I just need to add some more tests before I push it to github so we can discuss it futher.
Store some fields of SavedConfig in de-duplicated lists.
23Skidoo commentedon Oct 16, 2014
@erikd
ordNubdoes preserve the original ordering and is equivalent tonub. The reason I also added a right-biased variant is that with program options you want["-XNoFoo", "-XFoo"]mappend["-XNoFoo"]to result in["-XFoo", "-XNoFoo"]. Not sure if that's the case with paths, but you can of course use the left-biasedordNub.erikd commentedon Oct 16, 2014
Ah ok. I just assumed that because
ordNubrequired theOrdtypeclass constraint that it was returned the list ordered.With paths, I think left-biased makes more sense.
erikd commentedon Oct 16, 2014
Maybe we could define both left and right biased versions of NubList,
NubListLandNubListR.The nice thing about using a type rather than just defining functions to do this is that the types can enforce the invariants while maintaining the ability to just use
mappend.23Skidoo commentedon Oct 17, 2014
I'm +0 on using types for this. Usually we're not
mappendingNubLists themselves, but records that include them as members, for which one has to write boilerplateMonoidinstances anyway.erikd commentedon Oct 17, 2014
The fact that the records are
mappened-ed is exactly why you need to components inside the record to do the right thing by default. That is why you want to encode the right bechaviour in the types.bitemyapp commentedon Oct 17, 2014
@23Skidoo in lieu of a much more time intensive and possibly harder to understand data structure that probably wouldn't be worth it, NubList is the right way to do this in my opinion. They're typically small lists and fixing the correctness problem in this manner is more "by construction" than the code it replaced.
I'm +1 on NubList, for whatever that's worth.
cartazio commentedon Oct 17, 2014
I like newtypes because they document invariants.
edit: document and enforce
23Skidoo commentedon Oct 18, 2014
OK, let's add a newtype (
NubList/NubListR), but make it useordNubandlistUnionfrom #2111.No-one was suggesting adding a different data structure.
23Skidoo commentedon Oct 18, 2014
@erikd Can you please split
NubList-related commits from #2159 into a separate pull request so that I could merge them more quickly?erikd commentedon Oct 19, 2014
The problem is that the tests I wrote for the feature I added were failing because of the existing behaviour
mappendon theSavedConfigtype. TheNubListcode therefore needs to be applied before adding the new features.I've lost count of how many times I rebased this set of commits, but I will do it once more.
cabal-install: Use NubList for list fields of SavedConfig.
erikd commentedon Oct 19, 2014
The NubList changes by themselves are in: #2167
The saved/user-config features require NubList.
23Skidoo commentedon Oct 19, 2014
Fixed by #2167.