<p dir="ltr">I guess these are equivalent to the simpler expressions</p>
<p dir="ltr">rnfLTR = foldl' (const rnf) ()<br>
rnfRTL = foldr' (\x _ -> rnf x) ()</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Jul 13, 2016 11:16 PM, "David Feuer" <<a href="mailto:david.feuer@gmail.com">david.feuer@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">As I describe in <a href="https://github.com/haskell/deepseq/issues/17" rel="noreferrer" target="_blank">https://github.com/haskell/deepseq/issues/17</a> it is<br>
possible to implement an NFData instance for any Foldable type, and we<br>
can offer a function to help do that:<br>
<br>
data Unit = Unit<br>
<br>
instance Monoid Unit where<br>
  mempty = Unit<br>
  Unit `mappend` Unit = Unit -- strict in both arguments, unlike ()<br>
<br>
rnfFoldable :: (Foldable f, NFData a) => f a -> ()<br>
rnfFoldable xs = foldMap (\x -> rnf x `seq` Unit) xs `seq` ()<br>
<br>
This could be used like so:<br>
<br>
instance NFData a => NFData (F a) where<br>
  rnf = rnfFoldable<br>
<br>
This version forces from left to right. It would be possible to offer<br>
another version that forces from right to left:<br>
<br>
data Unit2 = Unit2<br>
<br>
instance Monoid Unit2 where<br>
  mempty = Unit2<br>
  x `mappend` Unit2 = x `seq` Unit2<br>
<br>
rnfFoldableRTL :: (Foldable f, NFData a) => f a -> ()<br>
rnfFoldableRTL xs = foldMap (\x -> rnf x `seq` Unit2) xs `seq` ()<br>
</blockquote></div></div>