Copyright | [2016..2020] The Accelerate Team |
---|---|
License | BSD3 |
Maintainer | Trevor L. McDonell <trevor.mcdonell@gmail.com> |
Stability | experimental |
Portability | non-portable (GHC extensions) |
Safe Haskell | None |
Language | Haskell2010 |
Monoid instances for Accelerate
Since: 1.2.0.0
Synopsis
Documentation
class Semigroup a => Monoid a where #
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following:
- Right identity
x
<>
mempty
= x- Left identity
mempty
<>
x = x- Associativity
x
(<>
(y<>
z) = (x<>
y)<>
zSemigroup
law)- Concatenation
mconcat
=foldr
(<>
)mempty
The method names refer to the monoid of lists under concatenation, but there are many other instances.
Some types can be viewed as a monoid in more than one way,
e.g. both addition and multiplication on numbers.
In such cases we often define newtype
s and make those instances
of Monoid
, e.g. Sum
and Product
.
NOTE: Semigroup
is a superclass of Monoid
since base-4.11.0.0.
Identity of mappend
>>>
"Hello world" <> mempty
"Hello world"
An associative operation
NOTE: This method is redundant and has the default
implementation
since base-4.11.0.0.
Should it be implemented manually, since mappend
= (<>
)mappend
is a synonym for
(<>
), it is expected that the two functions are defined the same
way. In a future GHC release mappend
will be removed from Monoid
.
Fold a list using the monoid.
For most types, the default definition for mconcat
will be
used, but the function is included in the class definition so
that an optimized version can be provided for specific types.
>>>
mconcat ["Hello", " ", "Haskell", "!"]
"Hello Haskell!"
Instances
Monoid Ordering | Since: base-2.1 |
Monoid () | Since: base-2.1 |
Monoid All | Since: base-2.1 |
Monoid Any | Since: base-2.1 |
Monoid String | |
Monoid ShortByteString | |
Defined in Data.ByteString.Short.Internal mappend :: ShortByteString -> ShortByteString -> ShortByteString # mconcat :: [ShortByteString] -> ShortByteString # | |
Monoid ByteString | |
Defined in Data.ByteString.Lazy.Internal mempty :: ByteString # mappend :: ByteString -> ByteString -> ByteString # mconcat :: [ByteString] -> ByteString # | |
Monoid ByteString | |
Defined in Data.ByteString.Internal mempty :: ByteString # mappend :: ByteString -> ByteString -> ByteString # mconcat :: [ByteString] -> ByteString # | |
Monoid Builder | |
Monoid IntSet | |
Monoid Journal | |
Monoid Cover | |
Monoid CoverCount | |
Defined in Hedgehog.Internal.Property mempty :: CoverCount # mappend :: CoverCount -> CoverCount -> CoverCount # mconcat :: [CoverCount] -> CoverCount # | |
Monoid LabelName | |
Monoid ParseError | |
Defined in Options.Applicative.Types mempty :: ParseError # mappend :: ParseError -> ParseError -> ParseError # mconcat :: [ParseError] -> ParseError # | |
Monoid Completer | |
Monoid Doc | |
Monoid AnsiStyle |
|
Monoid ByteArray | |
Monoid OptionSet | Later options override earlier ones |
Monoid Slot | |
Monoid [a] | Since: base-2.1 |
Semigroup a => Monoid (Maybe a) | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 |
Monoid a => Monoid (IO a) | Since: base-4.9.0.0 |
Monoid p => Monoid (Par1 p) | Since: base-4.12.0.0 |
Monoid (Predicate a) | |
Monoid (Comparison a) | |
Defined in Data.Functor.Contravariant mempty :: Comparison a # mappend :: Comparison a -> Comparison a -> Comparison a # mconcat :: [Comparison a] -> Comparison a # | |
Monoid (Equivalence a) | |
Defined in Data.Functor.Contravariant mempty :: Equivalence a # mappend :: Equivalence a -> Equivalence a -> Equivalence a # mconcat :: [Equivalence a] -> Equivalence a # | |
(Ord a, Bounded a) => Monoid (Min a) | Since: base-4.9.0.0 |
(Ord a, Bounded a) => Monoid (Max a) | Since: base-4.9.0.0 |
Monoid m => Monoid (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup mempty :: WrappedMonoid m # mappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # mconcat :: [WrappedMonoid m] -> WrappedMonoid m # | |
Semigroup a => Monoid (Option a) | Since: base-4.9.0.0 |
Monoid a => Monoid (Identity a) | Since: base-4.9.0.0 |
Monoid (First a) | Since: base-2.1 |
Monoid (Last a) | Since: base-2.1 |
Monoid a => Monoid (Dual a) | Since: base-2.1 |
Monoid (Endo a) | Since: base-2.1 |
Num a => Monoid (Sum a) | Since: base-2.1 |
Num a => Monoid (Product a) | Since: base-2.1 |
Monoid a => Monoid (Down a) | Since: base-4.11.0.0 |
PrimType ty => Monoid (UArray ty) | |
PrimType ty => Monoid (Block ty) | |
Monoid (CountOf ty) | |
Num a => Monoid (Colour a) | |
Num a => Monoid (AlphaColour a) | |
Defined in Data.Colour.Internal mempty :: AlphaColour a # mappend :: AlphaColour a -> AlphaColour a -> AlphaColour a # mconcat :: [AlphaColour a] -> AlphaColour a # | |
Monoid (IntMap a) | |
Monoid (Seq a) | |
Ord a => Monoid (Set a) | |
(Semigroup a, Monoid a) => Monoid (Coverage a) | |
Prim a => Monoid (Vector a) | |
Storable a => Monoid (Vector a) | |
(Hashable a, Eq a) => Monoid (HashSet a) | O(n+m) To obtain good performance, the smaller set must be presented as the first argument. Examples
|
Monoid (Vector a) | |
Ord a => Monoid (Min a) | |
Ord a => Monoid (Max a) | |
Monoid (Leftmost a) | |
Monoid (Rightmost a) | |
Monoid (Doc a) | |
Monoid (Doc ann) |
|
Monoid (PrimArray a) | Since: primitive-0.6.4.0 |
Monoid (SmallArray a) | |
Defined in Data.Primitive.SmallArray mempty :: SmallArray a # mappend :: SmallArray a -> SmallArray a -> SmallArray a # mconcat :: [SmallArray a] -> SmallArray a # | |
Monoid (Array a) | |
Monoid (Doc a) | |
Monoid (MergeSet a) | |
(Monoid (Exp a), Elt a) => Monoid (Exp (Maybe a)) Source # | |
Monoid (Exp ()) Source # | |
(Elt a, Elt b, Monoid (Exp a), Monoid (Exp b)) => Monoid (Exp (a, b)) Source # | |
(Elt a, Elt b, Elt c, Monoid (Exp a), Monoid (Exp b), Monoid (Exp c)) => Monoid (Exp (a, b, c)) Source # | |
(Elt a, Elt b, Elt c, Elt d, Monoid (Exp a), Monoid (Exp b), Monoid (Exp c), Monoid (Exp d)) => Monoid (Exp (a, b, c, d)) Source # | |
(Elt a, Elt b, Elt c, Elt d, Elt e, Monoid (Exp a), Monoid (Exp b), Monoid (Exp c), Monoid (Exp d), Monoid (Exp e)) => Monoid (Exp (a, b, c, d, e)) Source # | |
(Ord a, Bounded a) => Monoid (Exp (Min a)) Source # | |
(Ord a, Bounded a) => Monoid (Exp (Max a)) Source # | |
Num a => Monoid (Exp (Sum a)) Source # | |
Num a => Monoid (Exp (Product a)) Source # | |
Monoid b => Monoid (a -> b) | Since: base-2.1 |
Monoid (U1 p) | Since: base-4.12.0.0 |
(Monoid a, Monoid b) => Monoid (a, b) | Since: base-2.1 |
Monoid a => Monoid (Op a b) | |
Monoid a => Monoid (ST s a) | Since: base-4.11.0.0 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Ord k => Monoid (Map k v) | |
(Monad m, Monoid a) => Monoid (GenT m a) | |
(Eq k, Hashable k) => Monoid (HashMap k v) | If a key occurs in both maps, the mapping from the first will be the mapping in the result. Examples
|
Monoid (ReifiedFold s a) | |
Defined in Control.Lens.Reified mempty :: ReifiedFold s a # mappend :: ReifiedFold s a -> ReifiedFold s a -> ReifiedFold s a # mconcat :: [ReifiedFold s a] -> ReifiedFold s a # | |
(Contravariant f, Applicative f) => Monoid (Folding f a) | |
Applicative f => Monoid (Traversed a f) | |
(Apply f, Applicative f) => Monoid (TraversedF a f) | |
Defined in Control.Lens.Internal.Fold mempty :: TraversedF a f # mappend :: TraversedF a f -> TraversedF a f -> TraversedF a f # mconcat :: [TraversedF a f] -> TraversedF a f # | |
Monad m => Monoid (Sequenced a m) | |
Monoid (f a) => Monoid (Indexing f a) |
|
Monoid (Deepening i a) | This is an illegal |
Monoid (f p) => Monoid (Rec1 f p) | Since: base-4.12.0.0 |
(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | Since: base-2.1 |
Monoid a => Monoid (Const a b) | Since: base-4.9.0.0 |
(Applicative f, Monoid a) => Monoid (Ap f a) | Since: base-4.12.0.0 |
Alternative f => Monoid (Alt f a) | Since: base-4.8.0.0 |
(Semigroup a, Monoid a) => Monoid (Tagged s a) | |
Monoid (ReifiedIndexedFold i s a) | |
Defined in Control.Lens.Reified mempty :: ReifiedIndexedFold i s a # mappend :: ReifiedIndexedFold i s a -> ReifiedIndexedFold i s a -> ReifiedIndexedFold i s a # mconcat :: [ReifiedIndexedFold i s a] -> ReifiedIndexedFold i s a # | |
Reifies s (ReifiedMonoid a) => Monoid (ReflectedMonoid a s) | |
Defined in Data.Reflection mempty :: ReflectedMonoid a s # mappend :: ReflectedMonoid a s -> ReflectedMonoid a s -> ReflectedMonoid a s # mconcat :: [ReflectedMonoid a s] -> ReflectedMonoid a s # | |
Monoid c => Monoid (K1 i c p) | Since: base-4.12.0.0 |
(Monoid (f p), Monoid (g p)) => Monoid ((f :*: g) p) | Since: base-4.12.0.0 |
(Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) | Since: base-2.1 |
Monoid (f p) => Monoid (M1 i c f p) | Since: base-4.12.0.0 |
Monoid (f (g p)) => Monoid ((f :.: g) p) | Since: base-4.12.0.0 |
(Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) | Since: base-2.1 |
Contravariant g => Monoid (BazaarT p g a b t) | |
(<>) :: Semigroup a => a -> a -> a infixr 6 #
An associative operation.
>>>
[1,2,3] <> [4,5,6]
[1,2,3,4,5,6]
Monoid under addition.
>>>
getSum (Sum 1 <> Sum 2 <> mempty)
3
Instances
Monoid under multiplication.
>>>
getProduct (Product 3 <> Product 4 <> mempty)
12
Product | |
|