Skip to content

Commit 9b1d9d4

Browse files
authored
Document Semigroup and Monoid instances (#1050)
Add Haddocks showing the definitions of (<>) and mempty.
1 parent 7c437d5 commit 9b1d9d4

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

containers/src/Data/IntMap/Internal.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,15 @@ infixl 9 !?,\\{-This comment teaches CPP correct behaviour -}
440440
Types
441441
--------------------------------------------------------------------}
442442

443+
-- | @mempty@ = 'empty'
443444
instance Monoid (IntMap a) where
444445
mempty = empty
445446
mconcat = unions
446447
mappend = (<>)
447448

448-
-- | @since 0.5.7
449+
-- | @(<>)@ = 'union'
450+
--
451+
-- @since 0.5.7
449452
instance Semigroup (IntMap a) where
450453
(<>) = union
451454
stimes = stimesIdempotentMonoid

containers/src/Data/IntSet/Internal.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,15 @@ type BitMap = Word
326326
deriving instance Lift IntSet
327327
#endif
328328

329+
-- | @mempty@ = 'empty'
329330
instance Monoid IntSet where
330331
mempty = empty
331332
mconcat = unions
332333
mappend = (<>)
333334

334-
-- | @since 0.5.7
335+
-- | @(<>)@ = 'union'
336+
--
337+
-- @since 0.5.7
335338
instance Semigroup IntSet where
336339
(<>) = union
337340
stimes = stimesIdempotentMonoid

containers/src/Data/Map/Internal.hs

+4-5
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,6 @@ m1 \\ m2 = difference m1 m2
464464
Size balanced trees.
465465
--------------------------------------------------------------------}
466466
-- | A Map from keys @k@ to values @a@.
467-
--
468-
-- The 'Semigroup' operation for 'Map' is 'union', which prefers
469-
-- values from the left operand. If @m1@ maps a key @k@ to a value
470-
-- @a1@, and @m2@ maps the same key to a different value @a2@, then
471-
-- their union @m1 <> m2@ maps @k@ to @a1@.
472467

473468
-- See Note: Order of constructors
474469
data Map k a = Bin {-# UNPACK #-} !Size !k a !(Map k a) !(Map k a)
@@ -485,11 +480,15 @@ type role Map nominal representational
485480
deriving instance (Lift k, Lift a) => Lift (Map k a)
486481
#endif
487482

483+
-- | @mempty@ = 'empty'
488484
instance (Ord k) => Monoid (Map k v) where
489485
mempty = empty
490486
mconcat = unions
491487
mappend = (<>)
492488

489+
-- | @(<>)@ = 'union'
490+
--
491+
-- @since 0.5.7
493492
instance (Ord k) => Semigroup (Map k v) where
494493
(<>) = union
495494
stimes = stimesIdempotentMonoid

containers/src/Data/Sequence/Internal.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1000,11 +1000,14 @@ instance Read1 Seq where
10001000
(xs,t) <- readLst s
10011001
pure (fromList xs, t)
10021002

1003+
-- | @mempty@ = 'empty'
10031004
instance Monoid (Seq a) where
10041005
mempty = empty
10051006
mappend = (Semigroup.<>)
10061007

1007-
-- | @since 0.5.7
1008+
-- | @(<>)@ = '(><)'
1009+
--
1010+
-- @since 0.5.7
10081011
instance Semigroup.Semigroup (Seq a) where
10091012
(<>) = (><)
10101013
stimes = cycleNTimes . fromIntegral

containers/src/Data/Set/Internal.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,15 @@ type role Set nominal
303303
deriving instance Lift a => Lift (Set a)
304304
#endif
305305

306+
-- | @mempty@ = 'empty'
306307
instance Ord a => Monoid (Set a) where
307308
mempty = empty
308309
mconcat = unions
309310
mappend = (<>)
310311

311-
-- | @since 0.5.7
312+
-- | @(<>)@ = 'union'
313+
--
314+
-- @since 0.5.7
312315
instance Ord a => Semigroup (Set a) where
313316
(<>) = union
314317
stimes = stimesIdempotentMonoid

0 commit comments

Comments
 (0)