[commit: packages/deepseq] master, wip/remove_ghc70_72_cpp: Add NFData instances for Functor Sum and Product (7ef5f11)

git at git.haskell.org git at git.haskell.org
Wed Jul 19 21:59:27 UTC 2017


Repository : ssh://git@git.haskell.org/deepseq

On branches: master,wip/remove_ghc70_72_cpp
Link       : http://git.haskell.org/packages/deepseq.git/commitdiff/7ef5f110ac77c20f0de157ef210bb87d62c80807

>---------------------------------------------------------------

commit 7ef5f110ac77c20f0de157ef210bb87d62c80807
Author: Pepe Iborra <pepeiborra at gmail.com>
Date:   Sat Apr 8 10:29:33 2017 +0100

    Add NFData instances for Functor Sum and Product


>---------------------------------------------------------------

7ef5f110ac77c20f0de157ef210bb87d62c80807
 Control/DeepSeq.hs | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/Control/DeepSeq.hs b/Control/DeepSeq.hs
index ca36cae..344991d 100644
--- a/Control/DeepSeq.hs
+++ b/Control/DeepSeq.hs
@@ -109,6 +109,8 @@ import Data.Semigroup as Semi
 #if MIN_VERSION_base(4,9,0)
 import GHC.Stack.Types ( CallStack(..), SrcLoc(..) )
 import Data.Functor.Compose
+import qualified Data.Functor.Sum as Functor
+import qualified Data.Functor.Product as Functor
 #elif MIN_VERSION_base(4,8,1)
 import GHC.Stack ( CallStack(..) )
 import GHC.SrcLoc ( SrcLoc(..) )
@@ -433,6 +435,21 @@ instance (NFData1 f, NFData1 g) => NFData1(Compose f g) where liftRnf r = liftRn
 -- | @since 1.4.3.0
 instance (NFData1 f, NFData1 g, NFData a) => NFData (Compose f g a) where rnf = rnf1
 
+-- | @since 1.4.3.0
+instance (NFData1 f, NFData1 g) => NFData1(Functor.Sum f g) where
+  liftRnf rnf0 (Functor.InL l) = liftRnf rnf0 l
+  liftRnf rnf0 (Functor.InR r) = liftRnf rnf0 r
+
+-- | @since 1.4.3.0
+instance (NFData1 f, NFData1 g, NFData a) => NFData(Functor.Sum f g a) where rnf = rnf1
+
+-- | @since 1.4.3.0
+instance (NFData1 f, NFData1 g) => NFData1(Functor.Product f g) where
+  liftRnf rnf0 (Functor.Pair f g) = liftRnf rnf0 f `seq` liftRnf rnf0 g
+
+-- | @since 1.4.3.0
+instance (NFData1 f, NFData1 g, NFData a) => NFData(Functor.Product f g a) where rnf = rnf1
+
 instance NFData a => NFData (Ratio a) where
 
 #else



More information about the ghc-commits mailing list