[commit: packages/deepseq] master, typeable-with-kinds: Add `NFData` instances for `Monoid` wrappers (693fe5a)

git at git.haskell.org git at git.haskell.org
Thu Mar 19 11:35:27 UTC 2015


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

On branches: master,typeable-with-kinds
Link       : http://git.haskell.org/packages/deepseq.git/commitdiff/693fe5a36f5c21b9f1e032f39731e252e41b0e05

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

commit 693fe5a36f5c21b9f1e032f39731e252e41b0e05
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Sun Nov 23 17:07:46 2014 +0100

    Add `NFData` instances for `Monoid` wrappers
    
    Specifically for `Data.Monoid.{Dual,First,Last,Any,All,Sum,Product}`


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

693fe5a36f5c21b9f1e032f39731e252e41b0e05
 Control/DeepSeq.hs | 27 +++++++++++++++++++++++++++
 changelog.md       |  1 +
 2 files changed, 28 insertions(+)

diff --git a/Control/DeepSeq.hs b/Control/DeepSeq.hs
index aebc5ba..6b4906f 100644
--- a/Control/DeepSeq.hs
+++ b/Control/DeepSeq.hs
@@ -64,6 +64,7 @@ import Data.Complex
 import Data.Array
 import Data.Fixed
 import Data.Version
+import Data.Monoid
 
 #if MIN_VERSION_base(4,7,0)
 import Data.Proxy ( Proxy(Proxy) )
@@ -269,6 +270,32 @@ instance NFData a => NFData [a] where
 instance (Ix a, NFData a, NFData b) => NFData (Array a b) where
     rnf x = rnf (bounds x, Data.Array.elems x)
 
+-- |/Since: 1.4.0.0/
+instance NFData a => NFData (Dual a) where
+    rnf = rnf . getDual
+
+-- |/Since: 1.4.0.0/
+instance NFData a => NFData (First a) where
+    rnf = rnf . getFirst
+
+-- |/Since: 1.4.0.0/
+instance NFData a => NFData (Last a) where
+    rnf = rnf . getLast
+
+-- |/Since: 1.4.0.0/
+instance NFData Any where rnf = rnf . getAny
+
+-- |/Since: 1.4.0.0/
+instance NFData All where rnf = rnf . getAll
+
+-- |/Since: 1.4.0.0/
+instance NFData a => NFData (Sum a) where
+    rnf = rnf . getSum
+
+-- |/Since: 1.4.0.0/
+instance NFData a => NFData (Product a) where
+    rnf = rnf . getProduct
+
 instance (NFData a, NFData b) => NFData (a,b) where
   rnf (x,y) = rnf x `seq` rnf y
 
diff --git a/changelog.md b/changelog.md
index 73490e3..1e6c805 100644
--- a/changelog.md
+++ b/changelog.md
@@ -20,6 +20,7 @@
      - `Data.Functor.Identity.Identity`
      - `Data.Proxy.Proxy`
      - `Numeric.Natural.Natural`
+     - `Data.Monoid.{Dual,First,Last,Any,All,Sum,Product}`
 
 ## 1.3.0.2  *Nov 2013*
 



More information about the ghc-commits mailing list