Skip to content

Commit

Permalink
NFData1,NFData2 instances for Data.Map (haskell#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Beacham committed Feb 20, 2024
1 parent 3c13e0b commit db41b77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions containers/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
`Data.IntSet.splitMember` are now strict in the key. Previously, the key was
ignored for an empty map or set. (Soumik Sarkar)

### Additions

* `Data.Map`: `NFData1`, `NFData2` instances (David Beacham)

## 0.7

### Breaking changes
Expand Down
10 changes: 9 additions & 1 deletion containers/src/Data/Map/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ import Data.Semigroup (Arg(..), Semigroup(stimes))
import Data.Semigroup (Semigroup((<>)))
#endif
import Control.Applicative (Const (..))
import Control.DeepSeq (NFData(rnf))
import Control.DeepSeq (NFData(rnf),NFData1(liftRnf),NFData2(liftRnf2))
import Data.Bits (shiftL, shiftR)
import qualified Data.Foldable as Foldable
import Data.Bifoldable
Expand Down Expand Up @@ -4363,6 +4363,14 @@ instance (NFData k, NFData a) => NFData (Map k a) where
rnf Tip = ()
rnf (Bin _ kx x l r) = rnf kx `seq` rnf x `seq` rnf l `seq` rnf r

instance NFData k => NFData1 (Map k) where
liftRnf _ Tip = ()
liftRnf rnfx (Bin sz kx x l r) = rnf sz `seq` rnf kx `seq` rnfx x `seq` liftRnf rnfx l `seq` liftRnf rnfx r

instance NFData2 Map where
liftRnf2 _ _ Tip = ()
liftRnf2 rnfkx rnfx (Bin sz kx x l r) = rnf sz `seq` rnfkx kx `seq` rnfx x `seq` liftRnf2 rnfkx rnfx l `seq` liftRnf2 rnfkx rnfx r

{--------------------------------------------------------------------
Read
--------------------------------------------------------------------}
Expand Down

0 comments on commit db41b77

Please sign in to comment.