haskell / deepseq

Deep evaluation of data structures
http://hackage.haskell.org/package/deepseq
Other
40 stars 29 forks source link

Add instances for GHC.Generics data types #64

Open nfrisby opened 3 years ago

nfrisby commented 3 years ago

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.

andrewthad commented 3 years ago

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?

chessai commented 3 years ago

+1 from me, seems perfectly reasonable

mixphix commented 2 years ago

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