Skip to content

Commit

Permalink
Implement sconcat for Intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
meooow25 committed Dec 19, 2024
1 parent b0b2cb5 commit dbf5b17
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 9 additions & 5 deletions containers/src/Data/IntSet/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,7 @@ import Data.Bits
import qualified Data.List as List
import Data.List.NonEmpty (NonEmpty(..))
import Data.Maybe (fromMaybe)
import Data.Semigroup
(Semigroup(stimes), stimesIdempotent, stimesIdempotentMonoid)
#if !(MIN_VERSION_base(4,11,0))
import Data.Semigroup (Semigroup((<>)))
#endif
import Data.Semigroup (Semigroup(..), stimesIdempotent, stimesIdempotentMonoid)
import Utils.Containers.Internal.Prelude hiding
(filter, foldr, foldl, foldl', foldMap, null, map)
import Prelude ()
Expand All @@ -224,6 +220,7 @@ import Data.IntSet.Internal.IntTreeCommons
import Data.Data (Data(..), Constr, mkConstr, constrIndex, DataType, mkDataType)
import qualified Data.Data
import Text.Read
import Data.Coerce (coerce)
#endif

#if __GLASGOW_HASKELL__
Expand Down Expand Up @@ -687,6 +684,13 @@ instance Semigroup Intersection where
stimes = stimesIdempotent
{-# INLINABLE stimes #-}

sconcat =
#ifdef __GLASGOW_HASKELL__
coerce intersections
#else
Intersection . intersections . fmap getIntersection
#endif

{--------------------------------------------------------------------
Symmetric difference
--------------------------------------------------------------------}
Expand Down
14 changes: 9 additions & 5 deletions containers/src/Data/Set/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,7 @@ import Prelude ()
import Control.Applicative (Const(..))
import qualified Data.List as List
import Data.Bits (shiftL, shiftR)
import Data.Semigroup (Semigroup(stimes))
#if !(MIN_VERSION_base(4,11,0))
import Data.Semigroup (Semigroup((<>)))
#endif
import Data.Semigroup (stimesIdempotentMonoid, stimesIdempotent)
import Data.Semigroup (Semigroup(..), stimesIdempotentMonoid, stimesIdempotent)
import Data.Functor.Classes
import Data.Functor.Identity (Identity)
import qualified Data.Foldable as Foldable
Expand All @@ -265,6 +261,7 @@ import Data.Data
import Language.Haskell.TH.Syntax (Lift)
-- See Note [ Template Haskell Dependencies ]
import Language.Haskell.TH ()
import Data.Coerce (coerce)
#endif


Expand Down Expand Up @@ -928,6 +925,13 @@ instance (Ord a) => Semigroup (Intersection a) where
stimes = stimesIdempotent
{-# INLINABLE stimes #-}

sconcat =
#ifdef __GLASGOW_HASKELL__
coerce intersections
#else
Intersection . intersections . fmap getIntersection
#endif

{--------------------------------------------------------------------
Symmetric difference
--------------------------------------------------------------------}
Expand Down

0 comments on commit dbf5b17

Please sign in to comment.