
Oops.. Probably I get why toList is preferred method for making instances :) My rnfFoldable does not work. But this version must be correct:
rnfFoldable :: (NFData a, Foldable f) => f a -> () rnfFoldable = Foldable.foldl (\z x -> rnf x `seq` z) ()
On Tue, Jul 12, 2011 at 6:21 PM, Alexey Karakulov
My proposal is qiute straightforward. The patch is attached and it's essence is in these lines:
instance NFData a => NFData (Data.Sequence.Seq a) where rnf = rnf . Foldable.toList
[Discussion part]
I choosed toList method to keep the code style, but I'm not sure it's efficient to create cons'es when we could just fold:
rnfFoldable :: (NFData a, Foldable f) => f a -> () rnfFoldable = Foldable.foldMap rnf
Or it's better to do this with foldl (while not so nice at is was with using () as monoid):
rnfFoldable = Foldable.foldl (const rnf) ()
There was a proposal to add strict folds to Foldable type class, so we can use foldl' there.
My proposal is to add the instance in either way.