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 | Safe-Inferred |
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 ByteArray | Since: base-4.17.0.0 |
Monoid All | Since: base-2.1 |
Monoid Any | Since: base-2.1 |
Monoid Builder | |
Monoid ByteString | |
Defined in Data.ByteString.Internal.Type mempty :: ByteString # mappend :: ByteString -> ByteString -> ByteString # mconcat :: [ByteString] -> ByteString # | |
Monoid ByteString | |
Defined in Data.ByteString.Lazy.Internal mempty :: ByteString # mappend :: ByteString -> ByteString -> ByteString # mconcat :: [ByteString] -> ByteString # | |
Monoid ShortByteString | |
Defined in Data.ByteString.Short.Internal mappend :: ShortByteString -> ShortByteString -> ShortByteString # mconcat :: [ShortByteString] -> ShortByteString # | |
Monoid IntSet | |
Monoid Ordering | Since: base-2.1 |
Monoid Slot | |
Monoid Cover | |
Monoid CoverCount | |
Defined in Hedgehog.Internal.Property mempty :: CoverCount # mappend :: CoverCount -> CoverCount -> CoverCount # mconcat :: [CoverCount] -> CoverCount # | |
Monoid Journal | |
Monoid LabelName | |
Monoid Completer | |
Monoid ParseError | |
Defined in Options.Applicative.Types mempty :: ParseError # mappend :: ParseError -> ParseError -> ParseError # mconcat :: [ParseError] -> ParseError # | |
Monoid OsString | "String-Concatenation" for |
Monoid PosixString | |
Defined in System.OsString.Internal.Types mempty :: PosixString # mappend :: PosixString -> PosixString -> PosixString # mconcat :: [PosixString] -> PosixString # | |
Monoid WindowsString | |
Defined in System.OsString.Internal.Types mempty :: WindowsString # mappend :: WindowsString -> WindowsString -> WindowsString # mconcat :: [WindowsString] -> WindowsString # | |
Monoid Doc | |
Monoid AnsiStyle |
|
Monoid OptionSet | |
Monoid Builder | |
Monoid () | Since: base-2.1 |
(Ord a, Bounded a) => Monoid (Exp (Max a)) Source # | |
(Ord a, Bounded a) => Monoid (Exp (Min a)) Source # | |
Num a => Monoid (Exp (Product a)) Source # | |
Num a => Monoid (Exp (Sum a)) Source # | |
(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 # | |
FiniteBits a => Monoid (And a) | This constraint is arguably too strong. However,
as some types (such as Since: base-4.16 |
FiniteBits a => Monoid (Iff a) | This constraint is arguably
too strong. However, as some types (such as Since: base-4.16 |
Bits a => Monoid (Ior a) | Since: base-4.16 |
Bits a => Monoid (Xor a) | Since: base-4.16 |
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 (Down a) | Since: base-4.11.0.0 |
(Ord a, Bounded a) => Monoid (Max a) | Since: base-4.9.0.0 |
(Ord a, Bounded a) => Monoid (Min 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 # | |
Monoid a => Monoid (Dual a) | Since: base-2.1 |
Monoid (Endo a) | Since: base-2.1 |
Num a => Monoid (Product a) | Since: base-2.1 |
Num a => Monoid (Sum a) | Since: base-2.1 |
Monoid a => Monoid (STM a) | Since: base-4.17.0.0 |
(Generic a, Monoid (Rep a ())) => Monoid (Generically a) | Since: base-4.17.0.0 |
Defined in GHC.Generics mempty :: Generically a # mappend :: Generically a -> Generically a -> Generically a # mconcat :: [Generically a] -> Generically a # | |
Monoid p => Monoid (Par1 p) | Since: base-4.12.0.0 |
Monoid (IntMap a) | |
Monoid (Seq a) | |
Monoid (MergeSet a) | |
Ord a => Monoid (Set a) | |
Monoid a => Monoid (IO a) | Since: base-4.9.0.0 |
(Semigroup a, Monoid a) => Monoid (Coverage a) | |
Monoid (DefaultProp a) | |
Defined in Options.Applicative.Builder.Internal mempty :: DefaultProp a # mappend :: DefaultProp a -> DefaultProp a -> DefaultProp a # mconcat :: [DefaultProp a] -> DefaultProp a # | |
Monoid (Doc a) | |
Monoid (Doc ann) |
|
Monoid (Array a) | |
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 a => Monoid (Q a) | Since: template-haskell-2.17.0.0 |
(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) | |
Prim a => Monoid (Vector a) | |
Monoid (Doc a) | |
Semigroup a => Monoid (Maybe a) | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 |
Monoid a => Monoid (a) | Since: base-4.15 |
Monoid [a] | Since: base-2.1 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Monoid (U1 p) | Since: base-4.12.0.0 |
Monoid a => Monoid (ST s a) | Since: base-4.11.0.0 |
Ord k => Monoid (Map k v) | |
Monoid (Format r (a -> r)) | Useful instance for applying two formatters to the same input
argument. For example: |
(Monad m, Monoid a) => Monoid (GenT m a) | |
Applicative f => Monoid (Traversed a f) | |
Monoid (Mod f 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 b => Monoid (a -> b) | Since: base-2.1 |
(Monoid a, Monoid b) => Monoid (a, b) | 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 |
Monoid (f p) => Monoid (Rec1 f p) | Since: base-4.12.0.0 |
(Semigroup a, Monoid a) => Monoid (Tagged s a) | |
(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | Since: base-2.1 |
(Monoid (f a), Monoid (g a)) => Monoid (Product f g a) | Since: base-4.16.0.0 |
(Monoid (f p), Monoid (g p)) => Monoid ((f :*: g) p) | Since: base-4.12.0.0 |
Monoid c => Monoid (K1 i c 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 (g a)) => Monoid (Compose f g a) | Since: base-4.16.0.0 |
Monoid (f (g p)) => Monoid ((f :.: g) p) | Since: base-4.12.0.0 |
Monoid (f p) => Monoid (M1 i c f 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 |
(<>) :: 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
Functor Sum Source # | |
MonadFix Sum | Since: base-4.8.0.0 |
Defined in Control.Monad.Fix | |
Foldable Sum | Since: base-4.8.0.0 |
Defined in Data.Foldable fold :: Monoid m => Sum m -> m # foldMap :: Monoid m => (a -> m) -> Sum a -> m # foldMap' :: Monoid m => (a -> m) -> Sum a -> m # foldr :: (a -> b -> b) -> b -> Sum a -> b # foldr' :: (a -> b -> b) -> b -> Sum a -> b # foldl :: (b -> a -> b) -> b -> Sum a -> b # foldl' :: (b -> a -> b) -> b -> Sum a -> b # foldr1 :: (a -> a -> a) -> Sum a -> a # foldl1 :: (a -> a -> a) -> Sum a -> a # elem :: Eq a => a -> Sum a -> Bool # maximum :: Ord a => Sum a -> a # | |
Traversable Sum | Since: base-4.8.0.0 |
Applicative Sum | Since: base-4.8.0.0 |
Functor Sum | Since: base-4.8.0.0 |
Monad Sum | Since: base-4.8.0.0 |
NFData1 Sum | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Generic1 Sum | |
(Lift Exp a, Elt (Plain a)) => Lift Exp (Sum a) Source # | |
Elt a => Unlift Exp (Sum (Exp a)) Source # | |
Unbox a => Vector Vector (Sum a) | |
Defined in Data.Vector.Unboxed.Base basicUnsafeFreeze :: Mutable Vector s (Sum a) -> ST s (Vector (Sum a)) Source # basicUnsafeThaw :: Vector (Sum a) -> ST s (Mutable Vector s (Sum a)) Source # basicLength :: Vector (Sum a) -> Int Source # basicUnsafeSlice :: Int -> Int -> Vector (Sum a) -> Vector (Sum a) Source # basicUnsafeIndexM :: Vector (Sum a) -> Int -> Box (Sum a) Source # basicUnsafeCopy :: Mutable Vector s (Sum a) -> Vector (Sum a) -> ST s () Source # | |
Unbox a => MVector MVector (Sum a) | |
Defined in Data.Vector.Unboxed.Base basicLength :: MVector s (Sum a) -> Int Source # basicUnsafeSlice :: Int -> Int -> MVector s (Sum a) -> MVector s (Sum a) Source # basicOverlaps :: MVector s (Sum a) -> MVector s (Sum a) -> Bool Source # basicUnsafeNew :: Int -> ST s (MVector s (Sum a)) Source # basicInitialize :: MVector s (Sum a) -> ST s () Source # basicUnsafeReplicate :: Int -> Sum a -> ST s (MVector s (Sum a)) Source # basicUnsafeRead :: MVector s (Sum a) -> Int -> ST s (Sum a) Source # basicUnsafeWrite :: MVector s (Sum a) -> Int -> Sum a -> ST s () Source # basicClear :: MVector s (Sum a) -> ST s () Source # basicSet :: MVector s (Sum a) -> Sum a -> ST s () Source # basicUnsafeCopy :: MVector s (Sum a) -> MVector s (Sum a) -> ST s () Source # basicUnsafeMove :: MVector s (Sum a) -> MVector s (Sum a) -> ST s () Source # basicUnsafeGrow :: MVector s (Sum a) -> Int -> ST s (MVector s (Sum a)) Source # | |
Eq a => Eq (Sum a) Source # | |
Ord a => Ord (Sum a) Source # | |
Defined in Data.Array.Accelerate.Data.Monoid (<) :: Exp (Sum a) -> Exp (Sum a) -> Exp Bool Source # (>) :: Exp (Sum a) -> Exp (Sum a) -> Exp Bool Source # (<=) :: Exp (Sum a) -> Exp (Sum a) -> Exp Bool Source # (>=) :: Exp (Sum a) -> Exp (Sum a) -> Exp Bool Source # min :: Exp (Sum a) -> Exp (Sum a) -> Exp (Sum a) Source # max :: Exp (Sum a) -> Exp (Sum a) -> Exp (Sum a) Source # compare :: Exp (Sum a) -> Exp (Sum a) -> Exp Ordering Source # | |
Elt a => Elt (Sum a) Source # | |
Data a => Data (Sum a) | Since: base-4.8.0.0 |
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Sum a -> c (Sum a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Sum a) # dataTypeOf :: Sum a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Sum a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Sum a)) # gmapT :: (forall b. Data b => b -> b) -> Sum a -> Sum a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Sum a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Sum a -> r # gmapQ :: (forall d. Data d => d -> u) -> Sum a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Sum a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Sum a -> m (Sum a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Sum a -> m (Sum a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Sum a -> m (Sum a) # | |
Num a => Monoid (Exp (Sum a)) Source # | |
Num a => Monoid (Sum a) | Since: base-2.1 |
Num a => Semigroup (Exp (Sum a)) Source # | Since: 1.2.0.0 |
Num a => Semigroup (Sum a) | Since: base-4.9.0.0 |
Bounded a => Bounded (Exp (Sum a)) Source # | |
Bounded a => Bounded (Sum a) | Since: base-2.1 |
Generic (Sum a) | |
Num a => Num (Exp (Sum a)) Source # | |
Defined in Data.Array.Accelerate.Data.Monoid (+) :: Exp (Sum a) -> Exp (Sum a) -> Exp (Sum a) # (-) :: Exp (Sum a) -> Exp (Sum a) -> Exp (Sum a) # (*) :: Exp (Sum a) -> Exp (Sum a) -> Exp (Sum a) # negate :: Exp (Sum a) -> Exp (Sum a) # abs :: Exp (Sum a) -> Exp (Sum a) # signum :: Exp (Sum a) -> Exp (Sum a) # fromInteger :: Integer -> Exp (Sum a) # | |
Num a => Num (Sum a) | Since: base-4.7.0.0 |
Read a => Read (Sum a) | Since: base-2.1 |
Show a => Show (Sum a) | Since: base-2.1 |
NFData a => NFData (Sum a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Eq a => Eq (Sum a) | Since: base-2.1 |
Ord a => Ord (Sum a) | Since: base-2.1 |
Prim a => Prim (Sum a) | Since: primitive-0.6.5.0 |
Defined in Data.Primitive.Types sizeOfType# :: Proxy (Sum a) -> Int# Source # sizeOf# :: Sum a -> Int# Source # alignmentOfType# :: Proxy (Sum a) -> Int# Source # alignment# :: Sum a -> Int# Source # indexByteArray# :: ByteArray# -> Int# -> Sum a Source # readByteArray# :: MutableByteArray# s -> Int# -> State# s -> (# State# s, Sum a #) Source # writeByteArray# :: MutableByteArray# s -> Int# -> Sum a -> State# s -> State# s Source # setByteArray# :: MutableByteArray# s -> Int# -> Int# -> Sum a -> State# s -> State# s Source # indexOffAddr# :: Addr# -> Int# -> Sum a Source # readOffAddr# :: Addr# -> Int# -> State# s -> (# State# s, Sum a #) Source # writeOffAddr# :: Addr# -> Int# -> Sum a -> State# s -> State# s Source # setOffAddr# :: Addr# -> Int# -> Int# -> Sum a -> State# s -> State# s Source # | |
Unbox a => Unbox (Sum a) | |
Defined in Data.Vector.Unboxed.Base | |
type Rep1 Sum | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal | |
newtype MVector s (Sum a) | |
Defined in Data.Vector.Unboxed.Base | |
type Plain (Sum a) Source # | |
Defined in Data.Array.Accelerate.Data.Monoid | |
type Rep (Sum a) | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal | |
newtype Vector (Sum a) | |
Defined in Data.Vector.Unboxed.Base |
Monoid under multiplication.
>>>
getProduct (Product 3 <> Product 4 <> mempty)
12
Product | |
|