| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Distribution.Compat.Semigroup
Description
Compatibility layer for Data.Semigroup
Synopsis
- class Semigroup a where
- (<>) :: a -> a -> a
- class Semigroup a => Monoid a where
- newtype All = All {}
- newtype Any = Any {}
- newtype First' a = First' {
- getFirst' :: a
- newtype Last' a = Last' {
- getLast' :: a
- newtype Option' a = Option' {
- getOption' :: Maybe a
- gmappend :: (Generic a, GSemigroup (Rep a)) => a -> a -> a
- gmempty :: (Generic a, GMonoid (Rep a)) => a
Documentation
class Semigroup a where Source #
The class of semigroups (types with an associative binary operation).
Instances should satisfy the following:
You can alternatively define sconcat instead of (<>), in which case the
laws are:
Since: base-4.9.0.0
Methods
(<>) :: a -> a -> a infixr 6 Source #
An associative operation.
Examples
>>>[1,2,3] <> [4,5,6][1,2,3,4,5,6]
>>>Just [1, 2, 3] <> Just [4, 5, 6]Just [1,2,3,4,5,6]
>>>putStr "Hello, " <> putStrLn "World!"Hello, World!
Instances
class Semigroup a => Monoid a where Source #
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)<>zSemigrouplaw)- Concatenation
mconcat=foldr(<>)mempty
You can alternatively define mconcat instead of mempty, in which case the
laws are:
- Unit
mconcat(purex) = x- Multiplication
mconcat(joinxss) =mconcat(fmapmconcatxss)- Subclass
mconcat(toListxs) =sconcatxs
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 newtypes and make those instances
of Monoid, e.g. Sum and Product.
NOTE: Semigroup is a superclass of Monoid since base-4.11.0.0.
Methods
Identity of mappend
Examples
>>>"Hello world" <> mempty"Hello world"
>>>mempty <> [1, 2, 3][1,2,3]
mappend :: a -> a -> a Source #
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
Boolean monoid under conjunction (&&).
All x <> All y = All (x && y)
Examples
>>>All True <> mempty <> All False)All {getAll = False}
>>>mconcat (map (\x -> All (even x)) [2,4,6,7,8])All {getAll = False}
>>>All True <> memptyAll {getAll = True}
Instances
| Binary All Source # | Since: binary-0.8.4.0 | ||||
| NFData All Source # | Since: deepseq-1.4.0.0 | ||||
Defined in Control.DeepSeq | |||||
| Monoid All Source # | Since: base-2.1 | ||||
| Semigroup All Source # | Since: base-4.9.0.0 | ||||
| Eq All Source # | Since: base-2.1 | ||||
| Ord All Source # | Since: base-2.1 | ||||
Defined in GHC.Internal.Data.Semigroup.Internal | |||||
| Data All Source # | Since: base-4.8.0.0 | ||||
Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> All -> c All Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c All Source # toConstr :: All -> Constr Source # dataTypeOf :: All -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c All) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c All) Source # gmapT :: (forall b. Data b => b -> b) -> All -> All Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> All -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> All -> r Source # gmapQ :: (forall d. Data d => d -> u) -> All -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> All -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> All -> m All Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> All -> m All Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> All -> m All Source # | |||||
| Bounded All Source # | Since: base-2.1 | ||||
| Generic All Source # | |||||
Defined in GHC.Internal.Data.Semigroup.Internal Associated Types
| |||||
| Read All Source # | Since: base-2.1 | ||||
| Show All Source # | Since: base-2.1 | ||||
| type Rep All Source # | Since: base-4.7.0.0 | ||||
Defined in GHC.Internal.Data.Semigroup.Internal | |||||
Boolean monoid under disjunction (||).
Any x <> Any y = Any (x || y)
Examples
>>>Any True <> mempty <> Any FalseAny {getAny = True}
>>>mconcat (map (\x -> Any (even x)) [2,4,6,7,8])Any {getAny = True}
>>>Any False <> memptyAny {getAny = False}
Instances
| Binary Any Source # | Since: binary-0.8.4.0 | ||||
| NFData Any Source # | Since: deepseq-1.4.0.0 | ||||
Defined in Control.DeepSeq | |||||
| Monoid Any Source # | Since: base-2.1 | ||||
| Semigroup Any Source # | Since: base-4.9.0.0 | ||||
| Eq Any Source # | Since: base-2.1 | ||||
| Ord Any Source # | Since: base-2.1 | ||||
Defined in GHC.Internal.Data.Semigroup.Internal | |||||
| Data Any Source # | Since: base-4.8.0.0 | ||||
Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Any -> c Any Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Any Source # toConstr :: Any -> Constr Source # dataTypeOf :: Any -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Any) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Any) Source # gmapT :: (forall b. Data b => b -> b) -> Any -> Any Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Any -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Any -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Any -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Any -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Any -> m Any Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Any -> m Any Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Any -> m Any Source # | |||||
| Bounded Any Source # | Since: base-2.1 | ||||
| Generic Any Source # | |||||
Defined in GHC.Internal.Data.Semigroup.Internal Associated Types
| |||||
| Read Any Source # | Since: base-2.1 | ||||
| Show Any Source # | Since: base-2.1 | ||||
| type Rep Any Source # | Since: base-4.7.0.0 | ||||
Defined in GHC.Internal.Data.Semigroup.Internal | |||||
A copy of First.
Instances
| Semigroup (First' a) Source # | |
| Eq a => Eq (First' a) Source # | |
| Ord a => Ord (First' a) Source # | |
Defined in Distribution.Compat.Semigroup | |
| Show a => Show (First' a) Source # | |
A copy of Last.
Instances
| Functor Last' Source # | |||||
| Structured a => Structured (Last' a) Source # | |||||
Defined in Distribution.Compat.Semigroup | |||||
| Binary a => Binary (Last' a) Source # | |||||
| Semigroup (Last' a) Source # | |||||
| Eq a => Eq (Last' a) Source # | |||||
| Ord a => Ord (Last' a) Source # | |||||
Defined in Distribution.Compat.Semigroup | |||||
| Generic (Last' a) Source # | |||||
Defined in Distribution.Compat.Semigroup Associated Types
| |||||
| Read a => Read (Last' a) Source # | |||||
| Show a => Show (Last' a) Source # | |||||
| type Rep (Last' a) Source # | |||||
Defined in Distribution.Compat.Semigroup | |||||
A wrapper around Maybe, providing the Semigroup and Monoid instances
implemented for Maybe since base-4.11.
Constructors
| Option' | |
Fields
| |
Instances
| Functor Option' Source # | |||||
| Structured a => Structured (Option' a) Source # | |||||
Defined in Distribution.Compat.Semigroup | |||||
| Binary a => Binary (Option' a) Source # | |||||
| Semigroup a => Monoid (Option' a) Source # | |||||
| Semigroup a => Semigroup (Option' a) Source # | |||||
| Eq a => Eq (Option' a) Source # | |||||
| Ord a => Ord (Option' a) Source # | |||||
Defined in Distribution.Compat.Semigroup | |||||
| Generic (Option' a) Source # | |||||
Defined in Distribution.Compat.Semigroup Associated Types
| |||||
| Read a => Read (Option' a) Source # | |||||
| Show a => Show (Option' a) Source # | |||||
| type Rep (Option' a) Source # | |||||
Defined in Distribution.Compat.Semigroup | |||||