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

Auto-derive SeqIsEval for Generic type #7

Open
aspiwack opened this issue Nov 9, 2022 · 3 comments
Open

Auto-derive SeqIsEval for Generic type #7

aspiwack opened this issue Nov 9, 2022 · 3 comments

Comments

@aspiwack
Copy link
Owner

aspiwack commented Nov 9, 2022

Idea suggested by @Profpatsch on twitter

We could add an instance instance (Generic a, …) => SeqIsEval a. This instance would check that every field is strict (is it possible in the generic framework? I expect it is. Though I imagine that it's a little bit of work).

This instance is overlapping, but there is no risk in overlapping instances here: SeqIsEval has trivial evidence, so is automatically coherent. On the other hand, we need to be a little careful with error messages, because the instance will always trigger. It needs to point the user in the right direction if it eventually fails.

@TeofilC
Copy link

TeofilC commented Nov 9, 2022

There's a similar idea in this issue haskell/deepseq#3 .
I developed the gist from there a bit to handle recursion here: https://gist.github.com/TeofilC/a85da6a388ec94e8acb1519886fbd2a7

A slightly different approach is taken here: https://gist.github.com/anka-213/440cfef8c8712f5df747029640cfe170

One thing to also watch out for is that newtypes need to be handled as a special case as their field is always DecidedLazy (cf. https://gitlab.haskell.org/ghc/ghc/-/issues/21380)

Hope these links help!

@aspiwack
Copy link
Owner Author

Beautiful! This is all very helpful, thank you. Especially the newtype thing. Newtypes are easy to detect in Generic if I remember correctly, but it's would be quite easy to overlook.

@aspiwack aspiwack added this to the Hackage release milestone Nov 19, 2022
@TeofilC
Copy link

TeofilC commented Feb 14, 2024

I've also recently published a library that uses TH to do this stuff that you might find useful: https://tracsis.github.io/th-deepstrict/

It's not on Hackage yet but should be in a couple of months

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

No branches or pull requests

2 participants