Copyright | [2016..2017] Trevor L. McDonell |
---|---|
License | BSD3 |
Maintainer | Trevor L. McDonell <tmcdonell@cse.unsw.edu.au> |
Stability | experimental |
Portability | non-portable (GHC extensions) |
Safe Haskell | None |
Language | Haskell2010 |
Monoid instances for Accelerate
Since: 1.2.0.0
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 laws:
x
<>
mempty
= xmempty
<>
x = xx
(<>
(y<>
z) = (x<>
y)<>
zSemigroup
law)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
An associative operation
NOTE: This method is redundant and has the default
implementation
since base-4.11.0.0.mappend
= '(<>)'
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.
Instances
Monoid under addition.
>>>
getSum (Sum 1 <> Sum 2 <> mempty)
3
Instances
Monad Sum | Since: 4.8.0.0 |
Functor Sum | Since: 4.8.0.0 |
MonadFix Sum | Since: 4.8.0.0 |
Applicative Sum | Since: 4.8.0.0 |
Foldable Sum | Since: 4.8.0.0 |
fold :: Monoid m => Sum m -> 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: 4.8.0.0 |
Representable Sum | |
NFData1 Sum | Since: 1.4.3.0 |
Functor Sum Source # | |
Elt a => Unlift Exp (Sum (Exp a)) Source # | |
(Lift Exp a, Elt (Plain a)) => Lift Exp (Sum a) Source # | |
Bounded a => Bounded (Sum a) | |
Bounded a => Bounded (Exp (Sum a)) # | |
Eq a => Eq (Sum a) | |
Num a => Num (Sum a) | |
Num a => Num (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) -> 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) # | |
Ord a => Ord (Sum a) | |
Read a => Read (Sum a) | |
Show a => Show (Sum a) | |
Generic (Sum a) | |
Num a => Semigroup (Sum a) | Since: 4.9.0.0 |
Num a => Semigroup (Exp (Sum a)) # | Since: 1.2.0.0 |
Num a => Monoid (Sum a) | Since: 2.1 |
Num a => Monoid (Exp (Sum a)) # | |
NFData a => NFData (Sum a) | Since: 1.4.0.0 |
Wrapped (Sum a) | |
(Eq a, Num a) => AsEmpty (Sum a) | |
Elt a => Elt (Sum a) Source # | |
Eq a => Eq (Sum a) Source # | |
Ord a => Ord (Sum a) 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 # (>=) :: 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 # | |
Generic1 Sum | |
t ~ Sum b => Rewrapped (Sum a) t | |
type Rep Sum | |
type Rep (Sum a) | |
type Unwrapped (Sum a) | |
type Plain (Sum a) Source # | |
type Rep1 Sum | |
Monoid under multiplication.
>>>
getProduct (Product 3 <> Product 4 <> mempty)
12
Product | |
|