deepseq icon indicating copy to clipboard operation
deepseq copied to clipboard

Add instances for GHC.Generics data types

Open nfrisby opened this issue 4 years ago • 3 comments

I'm currently in a situation where I want to rnf a value from an upstream library, but it doesn't define NFData instances.

It does, however, define a Generic instance. If there were NFData instances for the data types defined in GHC.Generics (eg U1 etc), I could write rnf . GHC.Generics.from. Alternatively, if deepseq exported its grnf definition, I could similarly write grnf . GHC.Generics.from.

Either of those would let me avoid something like an orphan instance etc. (Those can be harmless eg in exes or tests, but I try to avoid them in general.)

Are there pitfalls that would make exporting these instances/grnf a footgun for users, or would this merely provide users more options? Thanks.

nfrisby avatar Apr 09 '21 00:04 nfrisby

I think that defining instances for the types in GHC.Generics sounds reasonable. You'd need NFData1 for some of the stuff, but all the instances seem pretty straightforward. Any of the maintainers of this library have any thoughts?

andrewthad avatar Apr 13 '21 15:04 andrewthad

+1 from me, seems perfectly reasonable

chessai avatar Apr 13 '21 15:04 chessai

We have GNFData for these types. Would giving them plain NFData yield a greater benefit than exporting grnf?

mixphix avatar Dec 05 '21 02:12 mixphix