Skip to content
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

[#45] Rewrite to Multiple Public Libraries #46

Merged
merged 2 commits into from
Oct 16, 2019

Conversation

chshersh
Copy link
Contributor

@chshersh chshersh commented Oct 2, 2019

Resolves #45

This doesn't compile. I see the following parsing error with this executable stanza:

Errors encountered when parsing cabal file ./containers-backpack.cabal:

containers-backpack.cabal:142:43: error:
unexpected ':'
expecting "-", white space, "(", "hiding", "requires", comma or end of input

  140 |   build-depends:       containers-backpack:{ int-strict, ordered-strict, unordered-strict, contrib }
  141 | 
  142 |   mixins:              containers-backpack:contrib (Map.Contrib.Group as Map.Contrib.Group.Int)
      |                                           ^

Unfortunately, this means that the interface is not usable at the moment until this bug is fixed in cabal. There were some other issues, like problems with having two signatures for readonly and not only containers, but they are solvable, and this one is show-stopper 😞

However, you can have an example of how better it will become!

@chshersh chshersh added enhancement New feature or request refactoring labels Oct 2, 2019
@chshersh chshersh requested a review from vrom911 October 2, 2019 17:25
@chshersh chshersh self-assigned this Oct 2, 2019
@chshersh chshersh force-pushed the chshersh/45-Rewrite-to-Multiple-Public-Libraries branch from d202996 to c48a96d Compare October 2, 2019 17:28
@chshersh
Copy link
Contributor Author

chshersh commented Oct 2, 2019

Copy link
Member

@vrom911 vrom911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks a lot for your work, that's great 👏 I would love to see those changes 👍

I have a couple of questions though:

  • Why cabal.project is not needed anymore?
  • It's actually nice that there is a central CHANGELOG but how it suppose to work for several standalone libraries?
  • Could we at least move the nice refactoring parts and merge them in master now, while waiting for the bugs to be resolved?





Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a generated file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's not generated. There were two signatures before: for readonly containers and for modifiable containers. But this doesn't work for some reason in this new solution. So I have only one file now, but haven't deleted old files yet. Will cleanup later 👍

update :: Key k => (a -> Maybe a) -> k -> Map k a -> Map k a
delete :: Key k => k -> Map k v -> Map k v
alter :: Key k => (Maybe v -> Maybe v) -> k -> Map k v -> Map k v

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we ask GitHub to highlight hsig files as Haskell? 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also would love to highlight them in my editor 🙂 But I don't know how to do this...

@chshersh
Copy link
Contributor Author

chshersh commented Oct 3, 2019

@vrom911 Thanks for your review! Answering your questions:

  1. It was a multipackage project before. But now there's only a single package. So cabal.project is not needed anymore 🙂
  2. If I understand correctly, you can't specify different versions for different multiple public libraries. So I'm not sure how you can specify different versions of sublibraries. This is a new approach and we have to figure out how to support and maintain such libraries...
  3. Yes, this sounds reasonable 👍 Pushing refactorings via a separate PR will make this PR smaller and easier to re-review in future.

@chshersh chshersh force-pushed the chshersh/45-Rewrite-to-Multiple-Public-Libraries branch 2 times, most recently from 910ff5d to 1108e9e Compare October 15, 2019 15:33
@chshersh chshersh force-pushed the chshersh/45-Rewrite-to-Multiple-Public-Libraries branch from 1108e9e to b60babb Compare October 15, 2019 15:39
@chshersh chshersh marked this pull request as ready for review October 15, 2019 15:39
@chshersh
Copy link
Contributor Author

@vrom911 This PR is ready for review! It finally builds locally, the executable is working, all tests are passing, benchmarks are running. Some highlights and summary of changes:

  1. Now instead of many small packages, we have a single package with multiple public libraries.
  2. To depend on a library, you need to write dependency like this:
    containers-backpack:ord-strict
    
    where containers-backpack is the name of this package (we can rename it any time, any suggestions are welcome) and ord-strict is the name of a public library inside this package.
  3. However, sometimes this doesn't work inside the package itself. So I just specify dependency simply as ord-strict. This is due to Cabal bugs.
  4. I merged readonly signatures and modifiable signatures. They complicated things a lot. I left primitive-containers package for now. But probably we should drop support for it eventually. We can't support it completely anyway (it has 5 different Map data types and we support only one at the moment).

Any feedback is appreciated!

Copy link
Member

@vrom911 vrom911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great to see that you made it work and simplified things a lot! Well done 👍

ViewPatterns

-- signatures for containers
library sig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there is no difference between internal libraries and libraries to export?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's my fault, turns out that all these libraries are indeed internal at the moment. To make them public, I needed to add visibility: public field. And, again, the documentation doesn't really help here...

https://www.haskell.org/cabal/users-guide/developing-packages.html#pkg-field-library-visibility
https://www.haskell.org/cabal/users-guide/developing-packages.html#pkg-section-library-library

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😞 we need to write more about such things in public so other people at least would be able to find these tricks easier...

test/Main.hs Outdated


-- | ShortText is a Text with length [0, 3] chosen "arbitrarily"
newtype ShortText = ShortText Text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be named field unShortText?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vrom911 Yes, I guess it should be made according to our style guide. This code was written a long time ago...

test/Main.hs Outdated
main = do
Int.checkLaws (Proxy @Int) (Proxy @V)
Ord.checkLaws (Proxy @K) (Proxy @V)
Hash.checkLaws (Proxy @K) (Proxy @V)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we fix indentation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Sorry, too many changes, forgot to fix everything...

Note: do not make minimum larger than 0, empty texts are often edge cases.
-}
instance Arbitrary ShortText where
arbitrary = ShortText . T.pack <$> (choose (0, 3) >>= flip vectorOf arbitrary)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add the signature if possible?

@chshersh chshersh force-pushed the chshersh/45-Rewrite-to-Multiple-Public-Libraries branch from c1617fc to a1ccb7f Compare October 16, 2019 06:16
Copy link
Member

@vrom911 vrom911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks for the massive work!

-- signatures for containers
library sig
import: common-options
visibility: public
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@vrom911 vrom911 merged commit 23f052c into master Oct 16, 2019
@vrom911 vrom911 deleted the chshersh/45-Rewrite-to-Multiple-Public-Libraries branch October 16, 2019 06:27
@chshersh chshersh added the Hacktoberfest https://hacktoberfest.digitalocean.com/ label Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Hacktoberfest https://hacktoberfest.digitalocean.com/ refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite to Multiple Public Libraries
2 participants