zero-0.1.5: Semigroups with absorption

Copyright(C) 2015 Dimitri Sabadie
LicenseBSD3
MaintainerDimitri Sabadie <dimitri.sabadie@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Data.Zero

Contents

Description

 
Synopsis

Semigroups with absorbing element

class Semigroup a => Zero a where Source #

Semigroup with a zero element. It’s important to understand that the standard Semigroup types – i.e. Maybe and so on – are already biased, because they’re Monoids. That’s why you’ll find a few Zero instances.

Should satisfies the following laws:

Annihilation

 a <> zero = zero <> a = zero

Associativity

 a <> b <> c = (a <> b) <> c = a <> (b <> c)

Minimal complete definition

zero

Methods

zero :: a Source #

The zero element.

zconcat :: [a] -> a Source #

Concat all the elements according to (<>) and zero.

zconcat :: [a] -> a Source #

Concat all the elements according to (<>) and zero.

Instances
Zero () Source # 
Instance details

Defined in Data.Zero

Methods

zero :: () Source #

zconcat :: [()] -> () Source #

Zero All Source # 
Instance details

Defined in Data.Zero

Methods

zero :: All Source #

zconcat :: [All] -> All Source #

Zero Any Source # 
Instance details

Defined in Data.Zero

Methods

zero :: Any Source #

zconcat :: [Any] -> Any Source #

Num a => Zero (Product a) Source # 
Instance details

Defined in Data.Zero

Methods

zero :: Product a Source #

zconcat :: [Product a] -> Product a Source #

Semigroup a => Zero (Success a) Source # 
Instance details

Defined in Data.Zero

Methods

zero :: Success a Source #

zconcat :: [Success a] -> Success a Source #

Num wrappers

newtype Product a #

Monoid under multiplication.

>>> getProduct (Product 3 <> Product 4 <> mempty)
12

Constructors

Product 

Fields

Instances
Monad Product

Since: base-4.8.0.0

Instance details

Defined in Data.Semigroup.Internal

Methods

(>>=) :: Product a -> (a -> Product b) -> Product b #

(>>) :: Product a -> Product b -> Product b #

return :: a -> Product a #

fail :: String -> Product a #

Functor Product

Since: base-4.8.0.0

Instance details

Defined in Data.Semigroup.Internal

Methods

fmap :: (a -> b) -> Product a -> Product b #

(<$) :: a -> Product b -> Product a #

MonadFix Product

Since: base-4.8.0.0

Instance details

Defined in Control.Monad.Fix

Methods

mfix :: (a -> Product a) -> Product a #

Applicative Product

Since: base-4.8.0.0

Instance details

Defined in Data.Semigroup.Internal

Methods

pure :: a -> Product a #

(<*>) :: Product (a -> b) -> Product a -> Product b #

liftA2 :: (a -> b -> c) -> Product a -> Product b -> Product c #

(*>) :: Product a -> Product b -> Product b #

(<*) :: Product a -> Product b -> Product a #

Foldable Product

Since: base-4.8.0.0

Instance details

Defined in Data.Foldable

Methods

fold :: Monoid m => Product m -> m #

foldMap :: Monoid m => (a -> m) -> Product a -> m #

foldr :: (a -> b -> b) -> b -> Product a -> b #

foldr' :: (a -> b -> b) -> b -> Product a -> b #

foldl :: (b -> a -> b) -> b -> Product a -> b #

foldl' :: (b -> a -> b) -> b -> Product a -> b #

foldr1 :: (a -> a -> a) -> Product a -> a #

foldl1 :: (a -> a -> a) -> Product a -> a #

toList :: Product a -> [a] #

null :: Product a -> Bool #

length :: Product a -> Int #

elem :: Eq a => a -> Product a -> Bool #

maximum :: Ord a => Product a -> a #

minimum :: Ord a => Product a -> a #

sum :: Num a => Product a -> a #

product :: Num a => Product a -> a #

Traversable Product

Since: base-4.8.0.0

Instance details

Defined in Data.Traversable

Methods

traverse :: Applicative f => (a -> f b) -> Product a -> f (Product b) #

sequenceA :: Applicative f => Product (f a) -> f (Product a) #

mapM :: Monad m => (a -> m b) -> Product a -> m (Product b) #

sequence :: Monad m => Product (m a) -> m (Product a) #

Bounded a => Bounded (Product a)

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Eq a => Eq (Product a)

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

(==) :: Product a -> Product a -> Bool #

(/=) :: Product a -> Product a -> Bool #

Num a => Num (Product a)

Since: base-4.7.0.0

Instance details

Defined in Data.Semigroup.Internal

Methods

(+) :: Product a -> Product a -> Product a #

(-) :: Product a -> Product a -> Product a #

(*) :: Product a -> Product a -> Product a #

negate :: Product a -> Product a #

abs :: Product a -> Product a #

signum :: Product a -> Product a #

fromInteger :: Integer -> Product a #

Ord a => Ord (Product a)

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

compare :: Product a -> Product a -> Ordering #

(<) :: Product a -> Product a -> Bool #

(<=) :: Product a -> Product a -> Bool #

(>) :: Product a -> Product a -> Bool #

(>=) :: Product a -> Product a -> Bool #

max :: Product a -> Product a -> Product a #

min :: Product a -> Product a -> Product a #

Read a => Read (Product a)

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Show a => Show (Product a)

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

showsPrec :: Int -> Product a -> ShowS #

show :: Product a -> String #

showList :: [Product a] -> ShowS #

Generic (Product a) 
Instance details

Defined in Data.Semigroup.Internal

Associated Types

type Rep (Product a) :: Type -> Type #

Methods

from :: Product a -> Rep (Product a) x #

to :: Rep (Product a) x -> Product a #

Num a => Semigroup (Product a)

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup.Internal

Methods

(<>) :: Product a -> Product a -> Product a #

sconcat :: NonEmpty (Product a) -> Product a #

stimes :: Integral b => b -> Product a -> Product a #

Num a => Monoid (Product a)

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

mempty :: Product a #

mappend :: Product a -> Product a -> Product a #

mconcat :: [Product a] -> Product a #

Num a => Zero (Product a) Source # 
Instance details

Defined in Data.Zero

Methods

zero :: Product a Source #

zconcat :: [Product a] -> Product a Source #

Generic1 Product 
Instance details

Defined in Data.Semigroup.Internal

Associated Types

type Rep1 Product :: k -> Type #

Methods

from1 :: Product a -> Rep1 Product a #

to1 :: Rep1 Product a -> Product a #

type Rep (Product a)

Since: base-4.7.0.0

Instance details

Defined in Data.Semigroup.Internal

type Rep (Product a) = D1 (MetaData "Product" "Data.Semigroup.Internal" "base" True) (C1 (MetaCons "Product" PrefixI True) (S1 (MetaSel (Just "getProduct") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a)))
type Rep1 Product

Since: base-4.7.0.0

Instance details

Defined in Data.Semigroup.Internal

type Rep1 Product = D1 (MetaData "Product" "Data.Semigroup.Internal" "base" True) (C1 (MetaCons "Product" PrefixI True) (S1 (MetaSel (Just "getProduct") NoSourceUnpackedness NoSourceStrictness DecidedLazy) Par1))

Boolean wrappers

newtype Any #

Boolean monoid under disjunction (||).

>>> getAny (Any True <> mempty <> Any False)
True
>>> getAny (mconcat (map (\x -> Any (even x)) [2,4,6,7,8]))
True

Constructors

Any 

Fields

Instances
Bounded Any

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

minBound :: Any #

maxBound :: Any #

Eq Any

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

(==) :: Any -> Any -> Bool #

(/=) :: Any -> Any -> Bool #

Ord Any

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

compare :: Any -> Any -> Ordering #

(<) :: Any -> Any -> Bool #

(<=) :: Any -> Any -> Bool #

(>) :: Any -> Any -> Bool #

(>=) :: Any -> Any -> Bool #

max :: Any -> Any -> Any #

min :: Any -> Any -> Any #

Read Any

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Show Any

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

showsPrec :: Int -> Any -> ShowS #

show :: Any -> String #

showList :: [Any] -> ShowS #

Generic Any 
Instance details

Defined in Data.Semigroup.Internal

Associated Types

type Rep Any :: Type -> Type #

Methods

from :: Any -> Rep Any x #

to :: Rep Any x -> Any #

Semigroup Any

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup.Internal

Methods

(<>) :: Any -> Any -> Any #

sconcat :: NonEmpty Any -> Any #

stimes :: Integral b => b -> Any -> Any #

Monoid Any

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

mempty :: Any #

mappend :: Any -> Any -> Any #

mconcat :: [Any] -> Any #

Zero Any Source # 
Instance details

Defined in Data.Zero

Methods

zero :: Any Source #

zconcat :: [Any] -> Any Source #

type Rep Any

Since: base-4.7.0.0

Instance details

Defined in Data.Semigroup.Internal

type Rep Any = D1 (MetaData "Any" "Data.Semigroup.Internal" "base" True) (C1 (MetaCons "Any" PrefixI True) (S1 (MetaSel (Just "getAny") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Bool)))

newtype All #

Boolean monoid under conjunction (&&).

>>> getAll (All True <> mempty <> All False)
False
>>> getAll (mconcat (map (\x -> All (even x)) [2,4,6,7,8]))
False

Constructors

All 

Fields

Instances
Bounded All

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

minBound :: All #

maxBound :: All #

Eq All

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

(==) :: All -> All -> Bool #

(/=) :: All -> All -> Bool #

Ord All

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

compare :: All -> All -> Ordering #

(<) :: All -> All -> Bool #

(<=) :: All -> All -> Bool #

(>) :: All -> All -> Bool #

(>=) :: All -> All -> Bool #

max :: All -> All -> All #

min :: All -> All -> All #

Read All

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Show All

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

showsPrec :: Int -> All -> ShowS #

show :: All -> String #

showList :: [All] -> ShowS #

Generic All 
Instance details

Defined in Data.Semigroup.Internal

Associated Types

type Rep All :: Type -> Type #

Methods

from :: All -> Rep All x #

to :: Rep All x -> All #

Semigroup All

Since: base-4.9.0.0

Instance details

Defined in Data.Semigroup.Internal

Methods

(<>) :: All -> All -> All #

sconcat :: NonEmpty All -> All #

stimes :: Integral b => b -> All -> All #

Monoid All

Since: base-2.1

Instance details

Defined in Data.Semigroup.Internal

Methods

mempty :: All #

mappend :: All -> All -> All #

mconcat :: [All] -> All #

Zero All Source # 
Instance details

Defined in Data.Zero

Methods

zero :: All Source #

zconcat :: [All] -> All Source #

type Rep All

Since: base-4.7.0.0

Instance details

Defined in Data.Semigroup.Internal

type Rep All = D1 (MetaData "All" "Data.Semigroup.Internal" "base" True) (C1 (MetaCons "All" PrefixI True) (S1 (MetaSel (Just "getAll") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Bool)))

Maybe wrappers

newtype Success a Source #

Zero for Maybe.

Called Success because of the absorbing law:

  Success (Just a) <> Success Nothing = Nothing

Constructors

Success 

Fields

Instances
Monad Success Source # 
Instance details

Defined in Data.Zero

Methods

(>>=) :: Success a -> (a -> Success b) -> Success b #

(>>) :: Success a -> Success b -> Success b #

return :: a -> Success a #

fail :: String -> Success a #

Functor Success Source # 
Instance details

Defined in Data.Zero

Methods

fmap :: (a -> b) -> Success a -> Success b #

(<$) :: a -> Success b -> Success a #

MonadFix Success Source # 
Instance details

Defined in Data.Zero

Methods

mfix :: (a -> Success a) -> Success a #

Applicative Success Source # 
Instance details

Defined in Data.Zero

Methods

pure :: a -> Success a #

(<*>) :: Success (a -> b) -> Success a -> Success b #

liftA2 :: (a -> b -> c) -> Success a -> Success b -> Success c #

(*>) :: Success a -> Success b -> Success b #

(<*) :: Success a -> Success b -> Success a #

Foldable Success Source # 
Instance details

Defined in Data.Zero

Methods

fold :: Monoid m => Success m -> m #

foldMap :: Monoid m => (a -> m) -> Success a -> m #

foldr :: (a -> b -> b) -> b -> Success a -> b #

foldr' :: (a -> b -> b) -> b -> Success a -> b #

foldl :: (b -> a -> b) -> b -> Success a -> b #

foldl' :: (b -> a -> b) -> b -> Success a -> b #

foldr1 :: (a -> a -> a) -> Success a -> a #

foldl1 :: (a -> a -> a) -> Success a -> a #

toList :: Success a -> [a] #

null :: Success a -> Bool #

length :: Success a -> Int #

elem :: Eq a => a -> Success a -> Bool #

maximum :: Ord a => Success a -> a #

minimum :: Ord a => Success a -> a #

sum :: Num a => Success a -> a #

product :: Num a => Success a -> a #

Traversable Success Source # 
Instance details

Defined in Data.Zero

Methods

traverse :: Applicative f => (a -> f b) -> Success a -> f (Success b) #

sequenceA :: Applicative f => Success (f a) -> f (Success a) #

mapM :: Monad m => (a -> m b) -> Success a -> m (Success b) #

sequence :: Monad m => Success (m a) -> m (Success a) #

Eq a => Eq (Success a) Source # 
Instance details

Defined in Data.Zero

Methods

(==) :: Success a -> Success a -> Bool #

(/=) :: Success a -> Success a -> Bool #

Ord a => Ord (Success a) Source # 
Instance details

Defined in Data.Zero

Methods

compare :: Success a -> Success a -> Ordering #

(<) :: Success a -> Success a -> Bool #

(<=) :: Success a -> Success a -> Bool #

(>) :: Success a -> Success a -> Bool #

(>=) :: Success a -> Success a -> Bool #

max :: Success a -> Success a -> Success a #

min :: Success a -> Success a -> Success a #

Read a => Read (Success a) Source # 
Instance details

Defined in Data.Zero

Show a => Show (Success a) Source # 
Instance details

Defined in Data.Zero

Methods

showsPrec :: Int -> Success a -> ShowS #

show :: Success a -> String #

showList :: [Success a] -> ShowS #

Semigroup a => Semigroup (Success a) Source # 
Instance details

Defined in Data.Zero

Methods

(<>) :: Success a -> Success a -> Success a #

sconcat :: NonEmpty (Success a) -> Success a #

stimes :: Integral b => b -> Success a -> Success a #

Semigroup a => Zero (Success a) Source # 
Instance details

Defined in Data.Zero

Methods

zero :: Success a Source #

zconcat :: [Success a] -> Success a Source #

success :: a -> Success a Source #

A successful value.

failure :: Success a Source #

A failure.