@@ -56,12 +56,8 @@ module Streamly.Internal.Data.SmallArray.Type
5656
5757import GHC.Exts hiding (toList)
5858import qualified GHC.Exts
59−
6059import Control.Applicative
6160import Control.Monad
62−#if MIN_VERSION_base(4,9,0)
63−import qualified Control.Monad.Fail as Fail
64−#endif
6561import Control.Monad.Fix
6662import Control.Monad.Primitive
6763import Control.Monad.ST
@@ -69,22 +65,12 @@ import Control.Monad.Zip
6965import Data.Data
7066import Data.Foldable as Foldable
7167import Data.Functor.Identity
72−#if !(MIN_VERSION_base(4,10,0))
73−import Data.Monoid
74−#endif
75−#if MIN_VERSION_base(4,9,0)
76−import qualified GHC.ST as GHCST
77−import qualified Data.Semigroup as Sem
78−#endif
79−import Text.ParserCombinators.ReadP
68+import Data.Functor.Classes (Eq1(..),Ord1(..),Show1(..),Read1(..))
8069
81−#if MIN_VERSION_base(4,9,0) && !MIN_VERSION_base(4,10,0)
82−import GHC.Base (runRW#)
83−#endif
70+import qualified Control.Monad.Fail as Fail
71+import qualified GHC.ST as GHCST
8472
85−#if MIN_VERSION_base(4,9,0) || MIN_VERSION_transformers(0,4,0)
86−import Data.Functor.Classes (Eq1(..),Ord1(..),Show1(..),Read1(..))
87−#endif
73+import Text.ParserCombinators.ReadP
8874
8975data SmallArray a = SmallArray (SmallArray# a)
9076 deriving Typeable
@@ -92,6 +78,7 @@ data SmallArray a = SmallArray (SmallArray# a)
9278data SmallMutableArray s a = SmallMutableArray (SmallMutableArray# s a)
9379 deriving Typeable
9480
81+
9582-- | Create a new small mutable array.
9683newSmallArray
9784 :: PrimMonad m
@@ -318,14 +305,6 @@ mapSmallArray' f sa = createSmallArray (length sa) (die "mapSmallArray'" "imposs
318305 let !y = f x
319306 writeSmallArray smb i y *> go (i+1)
320307{-# INLINE mapSmallArray' #-}
321−
322−#if !MIN_VERSION_base(4,9,0)
323−runSmallArray
324− :: (forall s. ST s (SmallMutableArray s a))
325− -> SmallArray a
326−runSmallArray m = runST $ m >>= unsafeFreezeSmallArray
327−
328−#else
329308-- This low-level business is designed to work with GHC's worker-wrapper
330309-- transformation. A lot of the time, we don't actually need an Array
331310-- constructor. By putting it on the outside, and being careful about
@@ -348,8 +327,6 @@ runSmallArray# m = case runRW# $ \s ->
348327unST :: ST s a -> State# s -> (# State# s, a #)
349328unST (GHCST.ST f) = f
350329
351−#endif
352−
353330-- See the comment on runSmallArray for why we use emptySmallArray#.
354331createSmallArray
355332 :: Int
@@ -393,20 +370,11 @@ smallArrayLiftEq p sa1 sa2 = length sa1 == length sa2 && loop (length sa1 - 1)
393370 | (# x #) <- indexSmallArray## sa1 i
394371 , (# y #) <- indexSmallArray## sa2 i
395372 = p x y && loop (i-1)
396−
397−#if MIN_VERSION_base(4,9,0) || MIN_VERSION_transformers(0,4,0)
398−-- | @since 0.6.4.0
399373instance Eq1 SmallArray where
400−#if MIN_VERSION_base(4,9,0) || MIN_VERSION_transformers(0,5,0)
401374 liftEq = smallArrayLiftEq
402−#else
403− eq1 = smallArrayLiftEq (==)
404−#endif
405−#endif
406375
407376instance Eq a => Eq (SmallArray a) where
408377 sa1 == sa2 = smallArrayLiftEq (==) sa1 sa2
409−
410378instance Eq (SmallMutableArray s a) where
411379 SmallMutableArray sma1# == SmallMutableArray sma2# =
412380 isTrue# (sameSmallMutableArray# sma1# sma2#)
@@ -422,15 +390,8 @@ smallArrayLiftCompare elemCompare a1 a2 = loop 0
422390 = elemCompare x1 x2 `mappend` loop (i+1)
423391 | otherwise = compare (length a1) (length a2)
424392
425−#if MIN_VERSION_base(4,9,0) || MIN_VERSION_transformers(0,4,0)
426−-- | @since 0.6.4.0
427393instance Ord1 SmallArray where
428−#if MIN_VERSION_base(4,9,0) || MIN_VERSION_transformers(0,5,0)
429394 liftCompare = smallArrayLiftCompare
430−#else
431− compare1 = smallArrayLiftCompare compare
432−#endif
433−#endif
434395
435396-- | Lexicographic ordering. Subject to change between major versions.
436397instance Ord a => Ord (SmallArray a) where
@@ -668,11 +629,8 @@ instance Monad SmallArray where
668629#if !(MIN_VERSION_base(4,13,0)) && MIN_VERSION_base(4,9,0)
669630 fail = Fail.fail
670631#endif
671−
672−#if MIN_VERSION_base(4,9,0)
673632instance Fail.MonadFail SmallArray where
674633 fail _ = emptySmallArray
675−#endif
676634
677635instance MonadPlus SmallArray where
678636 mzero = empty
@@ -715,24 +673,19 @@ instance MonadFix SmallArray where
715673 sz = sizeofSmallArray (f err)
716674 err = error "mfix for Data.Primitive.SmallArray applied to strict function."
717675
718−#if MIN_VERSION_base(4,9,0)
719676-- | @since 0.6.3.0
720−instance Sem.Semigroup (SmallArray a) where
677+instance Semigroup (SmallArray a) where
721678 (<>) = (<|>)
722− sconcat = mconcat . toList
723−#endif
724679
725680instance Monoid (SmallArray a) where
726681 mempty = empty
727−#if !(MIN_VERSION_base(4,11,0))
728− mappend = (<|>)
729−#endif
682+ mappend = (<>)
730683 mconcat l = createSmallArray n (die "mconcat" "impossible") $ \ma ->
731684 let go !_ [ ] = return ()
732685 go off (a:as) =
733686 copySmallArray ma off a 0 (sizeofSmallArray a) >> go (off + sizeofSmallArray a) as
734− in go 0 l
735− where n = sum . fmap length $ l
687+ in go 0 l
688+ where n = sum . fmap length $ l
736689
737690instance IsList (SmallArray a) where
738691 type Item (SmallArray a) = a
@@ -751,16 +704,8 @@ listLiftShowsPrec _ sl _ = sl
751704
752705instance Show a => Show (SmallArray a) where
753706 showsPrec = smallArrayLiftShowsPrec showsPrec showList
754−
755−#if MIN_VERSION_base(4,9,0) || MIN_VERSION_transformers(0,4,0)
756−-- | @since 0.6.4.0
757707instance Show1 SmallArray where
758−#if MIN_VERSION_base(4,9,0) || MIN_VERSION_transformers(0,5,0)
759708 liftShowsPrec = smallArrayLiftShowsPrec
760−#else
761− showsPrec1 = smallArrayLiftShowsPrec showsPrec showList
762−#endif
763−#endif
764709
765710smallArrayLiftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (SmallArray a)
766711smallArrayLiftReadsPrec _ listReadsPrec p = readParen (p > 10) . readP_to_S $ do
@@ -774,17 +719,8 @@ smallArrayLiftReadsPrec _ listReadsPrec p = readParen (p > 10) . readP_to_S $ do
774719instance Read a => Read (SmallArray a) where
775720 readsPrec = smallArrayLiftReadsPrec readsPrec readList
776721
777−#if MIN_VERSION_base(4,9,0) || MIN_VERSION_transformers(0,4,0)
778−-- | @since 0.6.4.0
779722instance Read1 SmallArray where
780−#if MIN_VERSION_base(4,9,0) || MIN_VERSION_transformers(0,5,0)
781723 liftReadsPrec = smallArrayLiftReadsPrec
782−#else
783− readsPrec1 = smallArrayLiftReadsPrec readsPrec readList
784−#endif
785−#endif
786−
787−
788724
789725smallArrayDataType :: DataType
790726smallArrayDataType =