add laws tests for Chunks

This commit is contained in:
Andrew Martin 2019-10-22 20:50:37 -04:00
parent da2be3281a
commit d66a9e6880
3 changed files with 31 additions and 0 deletions

View file

@ -27,6 +27,7 @@ import qualified Data.Primitive as PM
data Chunks
= ChunksCons {-# UNPACK #-} !Bytes !Chunks
| ChunksNil
deriving stock (Show)
instance Semigroup Chunks where
ChunksNil <> a = a
@ -37,6 +38,11 @@ instance Semigroup Chunks where
instance Monoid Chunks where
mempty = ChunksNil
instance Eq Chunks where
-- TODO: There is a more efficient way to do this, but
-- it is tedious.
a == b = concat a == concat b
concat :: Chunks -> ByteArray
concat x = ByteArray (concat# x)