haskell / haskell/deepseq

Offer Foldable helper

Open
#17 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Haskell
Stars
45
Forks
31
PR merge metrics
No merged PRs in 30d

Description

It's possible to define a reasonable `NFData` instance for any `Foldable` type. We can offer a suitable `rnf` to help.

``` haskell
data Unit = Unit

instance Monoid Unit where
mempty = Unit
Unit `mappend` Unit = Unit -- strict in both arguments, unlike ()

rnfFoldable :: (Foldable f, NFData a) => f a -> ()
rnfFoldable xs = foldMap (\x -> rnf x `seq` Unit) xs `seq` ()
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.