Skip to content

Commit 7ef5f11

Browse files
committed
Add NFData instances for Functor Sum and Product
1 parent e0f40eb commit 7ef5f11

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Control/DeepSeq.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ import Data.Semigroup as Semi
109109
#if MIN_VERSION_base(4,9,0)
110110
import GHC.Stack.Types ( CallStack(..), SrcLoc(..) )
111111
import Data.Functor.Compose
112+
import qualified Data.Functor.Sum as Functor
113+
import qualified Data.Functor.Product as Functor
112114
#elif MIN_VERSION_base(4,8,1)
113115
import GHC.Stack ( CallStack(..) )
114116
import GHC.SrcLoc ( SrcLoc(..) )
@@ -433,6 +435,21 @@ instance (NFData1 f, NFData1 g) => NFData1(Compose f g) where liftRnf r = liftRn
433435
-- | @since 1.4.3.0
434436
instance (NFData1 f, NFData1 g, NFData a) => NFData (Compose f g a) where rnf = rnf1
435437

438+
-- | @since 1.4.3.0
439+
instance (NFData1 f, NFData1 g) => NFData1(Functor.Sum f g) where
440+
liftRnf rnf0 (Functor.InL l) = liftRnf rnf0 l
441+
liftRnf rnf0 (Functor.InR r) = liftRnf rnf0 r
442+
443+
-- | @since 1.4.3.0
444+
instance (NFData1 f, NFData1 g, NFData a) => NFData(Functor.Sum f g a) where rnf = rnf1
445+
446+
-- | @since 1.4.3.0
447+
instance (NFData1 f, NFData1 g) => NFData1(Functor.Product f g) where
448+
liftRnf rnf0 (Functor.Pair f g) = liftRnf rnf0 f `seq` liftRnf rnf0 g
449+
450+
-- | @since 1.4.3.0
451+
instance (NFData1 f, NFData1 g, NFData a) => NFData(Functor.Product f g a) where rnf = rnf1
452+
436453
instance NFData a => NFData (Ratio a) where
437454

438455
#else

0 commit comments

Comments
 (0)