Skip to content

Commit

Permalink
Explicitly implement sconcat in Semigroup instances (#650)
Browse files Browse the repository at this point in the history
Since `stimes` was explicitly implemented in #611:
Closes #488. Closes #489.

(cherry picked from commit 93fdd3a)
  • Loading branch information
clyring committed Feb 5, 2024
1 parent 0dfc1b6 commit 502f2c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Data/ByteString/Builder/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ module Data.ByteString.Builder.Internal (
import Control.Arrow (second)

import Data.Semigroup (Semigroup(..))
import Data.List.NonEmpty (NonEmpty(..))

import qualified Data.ByteString as S
import qualified Data.ByteString.Internal.Type as S
Expand Down Expand Up @@ -400,6 +401,7 @@ stimesNegativeErr
instance Semigroup Builder where
{-# INLINE (<>) #-}
(<>) = append
sconcat (b:|bs) = b <> foldr mappend mempty bs
{-# INLINE stimes #-}
stimes = stimesBuilder

Expand Down
3 changes: 3 additions & 0 deletions Data/ByteString/Short/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ import Data.Monoid
( Monoid(..) )
import Data.Semigroup
( Semigroup(..), stimesMonoid )
import Data.List.NonEmpty
( NonEmpty(..) )
import Data.String
( IsString(..) )
import Control.Applicative
Expand Down Expand Up @@ -309,6 +311,7 @@ instance Ord ShortByteString where

instance Semigroup ShortByteString where
(<>) = append
sconcat (b:|bs) = concat (b:bs)
stimes = stimesMonoid

instance Monoid ShortByteString where
Expand Down

0 comments on commit 502f2c1

Please sign in to comment.