+1<br><br>I would just suggest calling the exported function `genericRnf`.<br><br><br>Cheers,<br>Pedro<br><br><div class="gmail_quote">On Fri, Sep 21, 2012 at 10:21 AM, Herbert Valerio Riedel <span dir="ltr"><<a href="mailto:hvr@gnu.org" target="_blank">hvr@gnu.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Simon (et al.),<br>
<br>
Some time ago, the `generic-deepseq` package was announced to the<br>
haskell-cafe list, and some discussion took place[1], and the suggestion<br>
came up that it might useful to be included to `deepseq` somehow.<br>
<br>
IMHO, a least introduing way (which I've been using myself) would be to<br>
add something along the code below to the `Control.DeepSeq` module (only<br>
`genericsRnf` shall be exported, thus avoiding a PVP-major-bump):<br>
<br>
<br>
-- | Generics-based 'rnf' implementation<br>
genericsRnf :: (Generic a, GNFData (Rep a)) => a -> ()<br>
genericsRnf = grnf_ . from<br>
{-# INLINE genericRnf #-}<br>
<br>
-- | Hidden type-class, /not/ exported<br>
class GNFData f where<br>
grnf_ :: f a -> ()<br>
<br>
instance GNFData U1 where<br>
grnf_ !U1 = ()<br>
{-# INLINE grnf_ #-}<br>
<br>
instance NFData a => GNFData (K1 i a) where<br>
grnf_ = rnf . unK1<br>
{-# INLINE grnf_ #-}<br>
<br>
instance GNFData a => GNFData (M1 i c a) where<br>
grnf_ = grnf_ . unM1<br>
{-# INLINE grnf_ #-}<br>
<br>
instance (GNFData a, GNFData b) => GNFData (a :*: b) where<br>
grnf_ (x :*: y) = grnf_ x `seq` grnf_ y<br>
{-# INLINE grnf_ #-}<br>
<br>
instance (GNFData a, GNFData b) => GNFData (a :+: b) where<br>
grnf_ (L1 x) = grnf_ x<br>
grnf_ (R1 x) = grnf_ x<br>
{-# INLINE grnf_ #-}<br>
<br>
<br>
<br>
this way, the client code can then chose to use a Generics-derived `rnf`<br>
implementation expliclity by simply declaring:<br>
<br>
instance NFData FooBar where rnf = genericsRnf<br>
<br>
<br>
...does this sound sensible?<br>
<br>
<br>
cheers,<br>
hvr<br>
<br>
[1]: <a href="http://www.haskell.org/pipermail/haskell-cafe/2012-February/099551.html" target="_blank">http://www.haskell.org/pipermail/haskell-cafe/2012-February/099551.html</a><br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
<br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/libraries" target="_blank">http://www.haskell.org/mailman/listinfo/libraries</a><br>
</font></span></blockquote></div><br>