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

Add generic machinery for Record instances #52

Merged

Conversation

JonathanLorimer
Copy link
Contributor

Submitter checklist

@JonathanLorimer
Copy link
Contributor Author

I had to do some module restructuring to avoid cyclic imports. I am happy to walk those changes back and just move everything to one module, or whatever you think is best for project structuring. This was just my initial take!

@@ -6,6 +6,8 @@ in with pkgs;
cabal-install
hlint
haskellPackages.apply-refact
haskellPackages.fourmolu
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it possible to specify the version? We're using v0.12 in the CI, it wouldn't be nice for people to land on another version :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you mind if I changed the shell.nix to a flake. Its really hard to control the dependency versions using (it just uses the nixpkgs that the users system has in scope, instead of a project specific pin).

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes feel free :)

Comment on lines +30 to +28
import Data.Text.Display.Core
import Data.Text.Display.Generic
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does this translate in terms of haddocks? Will people see barebones re-exports page?

Copy link
Collaborator

Choose a reason for hiding this comment

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

forget what I wrote, you fix this at the top it seems.

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 think so, but the documentation should be preserved on the module specific pages.

Comment on lines 83 to 88
-- | We leverage the `Generic.Data.GenericProduct` type to prevent consumers
-- from deriving instances for sum types. Sum types should use a manual instance
-- or derive one via `ShowInstance`.
--
-- @since 0.0.5.0
instance (Generic a, GDisplay1 (Rep a)) => Display (GenericProduct a) where
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know generic-data at all, what is the error message when you try to derive Display for a Sum?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is where it happens https://hackage.haskell.org/package/generic-data-1.1.0.0/docs/Generic-Data-Internal-Error.html#t:AssertNoSum. I agree that its not the best error message, but I was going to have to write some annoying type family machinery to get the appropriate custom error message, so I figured this was a fine interim solution.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. This might seem petty but I'm not too chuffed about the fact that generic-data transitively depends on array, stm, StateVar and contravariant.

How annoying would be the tyfam solution? More annoying than what was in the pg-entity code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me see. I think it actually shouldn't be too bad.

Copy link

Choose a reason for hiding this comment

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

Why do you not want to derive Display for sums? The GDisplay instance for (:+:) is fine, isn't it? As far as I can tell, this really is a better fit for Generically, which is defined in base recently.

GenericProduct on its own doesn't do anything different from Generically. It was meant to address a strange corner case of generic deriving for Monoid. If you want to forbid generic deriving on sums, it doesn't matter whether the type is named Generically or GenericProduct, you have to add the relevant error message to the (:+:) instance.

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'm open to Generically deriving the instances for Sums. I was just imagining that we wanted to constrain the way that some of the deriving via machinery was used. I actually just cribbed the AssertSum bit and placed it on the RecordInstance newtype.


-- |
-- Module : Data.Text.Display.Generic
-- Copyright : © Hécate Moonlight, 2021
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe you can put your name for the copyright :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I wasn't sure what to do there!

Comment on lines +156 to +158
-- > • 🚫 Cannot derive Display instance for MySum via RecordInstance due to sum type
-- > 💡 Sum types should use a manual instance or derive one via ShowInstance.
-- > • When deriving the instance for (Display MySum)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

@Kleidukos Kleidukos left a comment

Choose a reason for hiding this comment

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

Alright, I think there is only a changelog entry missing and that should be it. :)

@Kleidukos
Copy link
Collaborator

@JonathanLorimer would you mind rebasing on top of HEAD? :)

@JonathanLorimer JonathanLorimer force-pushed the jonathan/generic-record-machinery branch from ba52155 to e6a92d0 Compare May 16, 2023 15:33
@Kleidukos
Copy link
Collaborator

@JonathanLorimer I'll let you fix the hlint errors and I'll merge. Thanks a bunch for this PR!

@Kleidukos Kleidukos merged commit 692250f into haskell-text:main May 16, 2023
3 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants