diff options
author | Andreas Klebinger <klebinger.andreas@gmx.at> | 2022-03-15 14:19:40 +0100 |
---|---|---|
committer | Matthew Pickering <matthewtpickering@gmail.com> | 2022-04-01 11:01:35 +0100 |
commit | 6f4dc372d5c91686ad4148b82ad49a71d4dd82b5 (patch) | |
tree | cc52ce8addc819084dfdf47c84534066524d8e16 /libraries | |
parent | f589dea3b30695701ebcc0d742488290273d8cf2 (diff) | |
download | haskell-6f4dc372d5c91686ad4148b82ad49a71d4dd82b5.tar.gz |
Export MutableByteArray from Data.Array.Byte
This implements CLC proposal #49
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/Data/Array/Byte.hs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/libraries/base/Data/Array/Byte.hs b/libraries/base/Data/Array/Byte.hs index 7d43c03a31..2a49468be1 100644 --- a/libraries/base/Data/Array/Byte.hs +++ b/libraries/base/Data/Array/Byte.hs @@ -15,11 +15,12 @@ {-# LANGUAGE UnboxedTuples #-} module Data.Array.Byte ( - ByteArray(..) + ByteArray(..), + MutableByteArray(..), ) where import Data.Bits ((.&.), unsafeShiftR) -import Data.Data (mkNoRepType, Data(..)) +import Data.Data (mkNoRepType, Data(..), Typeable) import qualified Data.Foldable as F import Data.Semigroup import GHC.Show (intToDigit) @@ -39,6 +40,16 @@ import GHC.Word (Word8(..)) -- @since 4.17.0.0 data ByteArray = ByteArray ByteArray# +-- | Boxed wrapper for 'MutableByteArray#'. +-- +-- Since 'MutableByteArray#' is an unlifted type and not a member of kind 'Data.Kind.Type', +-- things like @[MutableByteArray#]@ or @IO MutableByteArray#@ are ill-typed. To work around this +-- inconvenience this module provides a standard boxed wrapper, inhabiting 'Data.Kind.Type'. +-- Clients are expected to use 'MutableByteArray' in higher-level APIs, +-- but wrap and unwrap 'MutableByteArray' internally as they please +-- and use functions from "GHC.Exts". +-- +-- @since 4.17.0.0 data MutableByteArray s = MutableByteArray (MutableByteArray# s) -- | Create a new mutable byte array of the specified size in bytes. @@ -121,6 +132,11 @@ instance Data ByteArray where gunfold _ _ = error "gunfold" dataTypeOf _ = mkNoRepType "Data.Array.Byte.ByteArray" +instance Typeable s => Data (MutableByteArray s) where + toConstr _ = error "toConstr" + gunfold _ _ = error "gunfold" + dataTypeOf _ = mkNoRepType "Data.Array.Byte.MutableByteArray" + instance Show ByteArray where showsPrec _ ba = showString "[" . go 0 @@ -160,6 +176,10 @@ instance Eq ByteArray where n1 = sizeofByteArray ba1 n2 = sizeofByteArray ba2 +instance Eq (MutableByteArray s) where + (==) (MutableByteArray arr#) (MutableByteArray brr#) + = isTrue# (sameMutableByteArray# arr# brr#) + -- | Non-lexicographic ordering. This compares the lengths of -- the byte arrays first and uses a lexicographic ordering if -- the lengths are equal. Subject to change between major versions. |