From 7336f018b80cc6651c74c99782d394bf9cb0f2b2 Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Thu, 5 Aug 2021 18:53:35 +0100 Subject: [PATCH] Add NFData instance for ByteArray --- Control/DeepSeq.hs | 17 +++++++++++++++++ changelog.md | 2 ++ 2 files changed, 19 insertions(+) diff --git a/Control/DeepSeq.hs b/Control/DeepSeq.hs index 00bb6fd..61c440e 100644 --- a/Control/DeepSeq.hs +++ b/Control/DeepSeq.hs @@ -21,6 +21,10 @@ {-# OPTIONS_GHC -Wno-deprecations #-} #endif +#define BYTEARRAY_IN_BASE (__GLASGOW_HASKELL__ >= 903) +-- At the moment of writing GHC source tree has not yet bumped `base` version, +-- so using __GLASGOW_HASKELL__ as a proxy instead of MIN_VERSION_base(4,17,0). + ----------------------------------------------------------------------------- -- | -- Module : Control.DeepSeq @@ -161,6 +165,10 @@ import GHC.Tuple (Solo (..)) #endif #endif +#if BYTEARRAY_IN_BASE +import Data.Array.Byte (ByteArray(..)) +#endif + -- | Hidden internal type-class class GNFData arity f where grnf :: RnfArgs arity a -> f a -> () @@ -1046,3 +1054,12 @@ instance (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFDa instance (NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7) => NFData2 ((,,,,,,,,) a1 a2 a3 a4 a5 a6 a7) where liftRnf2 r r' (x1,x2,x3,x4,x5,x6,x7,x8,x9) = rnf x1 `seq` rnf x2 `seq` rnf x3 `seq` rnf x4 `seq` rnf x5 `seq` rnf x6 `seq` rnf x7 `seq` r x8 `seq` r' x9 + +---------------------------------------------------------------------------- +-- ByteArray + +#if BYTEARRAY_IN_BASE +-- |@since 1.4.6.0 +instance NFData ByteArray where + rnf (ByteArray _) = () +#endif diff --git a/changelog.md b/changelog.md index 3368abf..921ff3e 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,8 @@ ([#69](https://github.com/haskell/deepseq/pull/69)) * Add once again `infixr 0 deepseq` ([#56](https://github.com/haskell/deepseq/pull/56), [#74](https://github.com/haskell/deepseq/issues/74)) + * Add `NFData` instance for `ByteArray` + ([#65](https://github.com/haskell/deepseq/pull/65)) ## 1.4.6.1