monoid-extras-0.7: Various extra monoid-related definitions and utilities

Copyright | (c) 2012-2015 diagrams-core team (see LICENSE)
License | BSD-style (see LICENSE)
Maintainer | diagrams-discuss@googlegroups.com
Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Monoid.Inf

Contents

- Type-restricted constructors

Description

Make semigroups under `min` or `max` into monoids by adjoining an element corresponding to infinity (positive or negative, respectively). These types are similar to `Maybe (Min a)` and `Maybe (Max a)` respectively, except that the `Ord` instance matches the `Monoid` instance.

Synopsis

- data Inf p a
  - = Infinity
  - | Finite a
- data Pos
- data Neg
- type PosInf a = Inf Pos a
- type NegInf a = Inf Neg a
- minimum :: Ord a => [a] -> PosInf a
- maximum :: Ord a => [a] -> NegInf a
- posInfty :: PosInf a
- negInfty :: NegInf a
- posFinite :: a -> PosInf a
- negFinite :: a -> NegInf a

# Documentation

data Inf p a Source #

`Inf p a` represents the type `a` extended with a new "infinite" value, which is treated as either positive or negative infinity depending on the type index `p`. This type exists mostly for its `Ord`, `Semigroup`, and `Monoid` instances.

Constructors

Infinity |
Finite a |

#### Instances

Instances details

Applicative (Inf p) Source # |
Instance details Defined in Data.Monoid.Inf Methods pure :: a -> Inf p a Source # (<*>) :: Inf p (a -> b) -> Inf p a -> Inf p b Source # liftA2 :: (a -> b -> c) -> Inf p a -> Inf p b -> Inf p c Source # (*>) :: Inf p a -> Inf p b -> Inf p b Source # (<*) :: Inf p a -> Inf p b -> Inf p a Source #
Functor (Inf p) Source # |
Instance details Defined in Data.Monoid.Inf Methods fmap :: (a -> b) -> Inf p a -> Inf p b Source # (<$) :: a -> Inf p b -> Inf p a Source #
Monad (Inf p) Source # |
Instance details Defined in Data.Monoid.Inf Methods (>>=) :: Inf p a -> (a -> Inf p b) -> Inf p b Source # (>>) :: Inf p a -> Inf p b -> Inf p b Source # return :: a -> Inf p a Source #
Foldable (Inf p) Source # |

Instance details

Defined in Data.Monoid.Inf

Methods

fold :: Monoid m => Inf p m -> m Source #

foldMap :: Monoid m => (a -> m) -> Inf p a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Inf p a -> m Source #

foldr :: (a -> b -> b) -> b -> Inf p a -> b Source #

foldr' :: (a -> b -> b) -> b -> Inf p a -> b Source #

foldl :: (b -> a -> b) -> b -> Inf p a -> b Source #

foldl' :: (b -> a -> b) -> b -> Inf p a -> b Source #

foldr1 :: (a -> a -> a) -> Inf p a -> a Source #

foldl1 :: (a -> a -> a) -> Inf p a -> a Source #

toList :: Inf p a -> [a] Source #

null :: Inf p a -> Bool Source #

length :: Inf p a -> Int Source #

elem :: Eq a => a -> Inf p a -> Bool Source #

maximum :: Ord a => Inf p a -> a Source #

minimum :: Ord a => Inf p a -> a Source #

sum :: Num a => Inf p a -> a Source #

product :: Num a => Inf p a -> a Source #

Traversable (Inf p) Source # |
Instance details Defined in Data.Monoid.Inf Methods traverse :: Applicative f => (a -> f b) -> Inf p a -> f (Inf p b) Source # sequenceA :: Applicative f => Inf p (f a) -> f (Inf p a) Source # mapM :: Monad m => (a -> m b) -> Inf p a -> m (Inf p b) Source # sequence :: Monad m => Inf p (m a) -> m (Inf p a) Source #
Bounded a => Bounded (NegInf a) Source # |
Instance details Defined in Data.Monoid.Inf Methods minBound :: NegInf a Source # maxBound :: NegInf a Source #
Bounded a => Bounded (PosInf a) Source # |
Instance details Defined in Data.Monoid.Inf Methods minBound :: PosInf a Source # maxBound :: PosInf a Source #
Ord a => Monoid (Inf Neg a) Source # | An ordered type extended with negative infinity is a monoid under `max`, with negative infinity as the identity element.
Instance details Defined in Data.Monoid.Inf Methods mempty :: Inf Neg a Source # mappend :: Inf Neg a -> Inf Neg a -> Inf Neg a Source # mconcat :: [Inf Neg a] -> Inf Neg a Source #
Ord a => Monoid (Inf Pos a) Source # | An ordered type extended with positive infinity is a monoid under `min`, with positive infinity as the identity element.
Instance details Defined in Data.Monoid.Inf Methods mempty :: Inf Pos a Source # mappend :: Inf Pos a -> Inf Pos a -> Inf Pos a Source # mconcat :: [Inf Pos a] -> Inf Pos a Source #
Ord a => Semigroup (Inf Neg a) Source # | An ordered type extended with negative infinity is a semigroup under `max`.
Instance details Defined in Data.Monoid.Inf Methods (<>) :: Inf Neg a -> Inf Neg a -> Inf Neg a Source # sconcat :: NonEmpty (Inf Neg a) -> Inf Neg a Source # stimes :: Integral b => b -> Inf Neg a -> Inf Neg a Source #
Ord a => Semigroup (Inf Pos a) Source # | An ordered type extended with positive infinity is a semigroup under `min`.
Instance details Defined in Data.Monoid.Inf Methods (<>) :: Inf Pos a -> Inf Pos a -> Inf Pos a Source # sconcat :: NonEmpty (Inf Pos a) -> Inf Pos a Source # stimes :: Integral b => b -> Inf Pos a -> Inf Pos a Source #
(Data p, Data a) => Data (Inf p a) Source # |

Instance details

Defined in Data.Monoid.Inf

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Inf p a -> c (Inf p a) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Inf p a) Source #

toConstr :: Inf p a -> Constr Source #

dataTypeOf :: Inf p a -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Inf p a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Inf p a)) Source #

gmapT :: (forall b. Data b => b -> b) -> Inf p a -> Inf p a Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Inf p a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Inf p a -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Inf p a -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Inf p a -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Inf p a -> m (Inf p a) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Inf p a -> m (Inf p a) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Inf p a -> m (Inf p a) Source #

Read a => Read (Inf p a) Source # |
Instance details Defined in Data.Monoid.Inf Methods readsPrec :: Int -> ReadS (Inf p a) Source # readList :: ReadS [Inf p a] Source # readPrec :: ReadPrec (Inf p a) Source # readListPrec :: ReadPrec [Inf p a] Source #
Show a => Show (Inf p a) Source # |
Instance details Defined in Data.Monoid.Inf Methods showsPrec :: Int -> Inf p a -> ShowS Source # show :: Inf p a -> String Source # showList :: [Inf p a] -> ShowS Source #
Eq a => Eq (Inf p a) Source # |
Instance details Defined in Data.Monoid.Inf Methods (==) :: Inf p a -> Inf p a -> Bool Source # (/=) :: Inf p a -> Inf p a -> Bool Source #
Ord a => Ord (Inf Neg a) Source # | Negative infinity is less than any finite value.
Instance details Defined in Data.Monoid.Inf Methods compare :: Inf Neg a -> Inf Neg a -> Ordering Source # (<) :: Inf Neg a -> Inf Neg a -> Bool Source # (<=) :: Inf Neg a -> Inf Neg a -> Bool Source # (>) :: Inf Neg a -> Inf Neg a -> Bool Source # (>=) :: Inf Neg a -> Inf Neg a -> Bool Source # max :: Inf Neg a -> Inf Neg a -> Inf Neg a Source # min :: Inf Neg a -> Inf Neg a -> Inf Neg a Source #
Ord a => Ord (Inf Pos a) Source # | Positive infinity is greater than any finite value.
Instance details Defined in Data.Monoid.Inf Methods compare :: Inf Pos a -> Inf Pos a -> Ordering Source # (<) :: Inf Pos a -> Inf Pos a -> Bool Source # (<=) :: Inf Pos a -> Inf Pos a -> Bool Source # (>) :: Inf Pos a -> Inf Pos a -> Bool Source # (>=) :: Inf Pos a -> Inf Pos a -> Bool Source # max :: Inf Pos a -> Inf Pos a -> Inf Pos a Source # min :: Inf Pos a -> Inf Pos a -> Inf Pos a Source #

data Pos Source #

Type index indicating positive infinity.

#### Instances

Instances details

Bounded a => Bounded (PosInf a) Source # |
Instance details Defined in Data.Monoid.Inf Methods minBound :: PosInf a Source # maxBound :: PosInf a Source #
Ord a => Monoid (Inf Pos a) Source # | An ordered type extended with positive infinity is a monoid under `min`, with positive infinity as the identity element.
Instance details Defined in Data.Monoid.Inf Methods mempty :: Inf Pos a Source # mappend :: Inf Pos a -> Inf Pos a -> Inf Pos a Source # mconcat :: [Inf Pos a] -> Inf Pos a Source #
Ord a => Semigroup (Inf Pos a) Source # | An ordered type extended with positive infinity is a semigroup under `min`.
Instance details Defined in Data.Monoid.Inf Methods (<>) :: Inf Pos a -> Inf Pos a -> Inf Pos a Source # sconcat :: NonEmpty (Inf Pos a) -> Inf Pos a Source # stimes :: Integral b => b -> Inf Pos a -> Inf Pos a Source #
Ord a => Ord (Inf Pos a) Source # | Positive infinity is greater than any finite value.
Instance details Defined in Data.Monoid.Inf Methods compare :: Inf Pos a -> Inf Pos a -> Ordering Source # (<) :: Inf Pos a -> Inf Pos a -> Bool Source # (<=) :: Inf Pos a -> Inf Pos a -> Bool Source # (>) :: Inf Pos a -> Inf Pos a -> Bool Source # (>=) :: Inf Pos a -> Inf Pos a -> Bool Source # max :: Inf Pos a -> Inf Pos a -> Inf Pos a Source # min :: Inf Pos a -> Inf Pos a -> Inf Pos a Source #

data Neg Source #

Type index indicating negative infinity.

#### Instances

Instances details

Bounded a => Bounded (NegInf a) Source # |
Instance details Defined in Data.Monoid.Inf Methods minBound :: NegInf a Source # maxBound :: NegInf a Source #
Ord a => Monoid (Inf Neg a) Source # | An ordered type extended with negative infinity is a monoid under `max`, with negative infinity as the identity element.
Instance details Defined in Data.Monoid.Inf Methods mempty :: Inf Neg a Source # mappend :: Inf Neg a -> Inf Neg a -> Inf Neg a Source # mconcat :: [Inf Neg a] -> Inf Neg a Source #
Ord a => Semigroup (Inf Neg a) Source # | An ordered type extended with negative infinity is a semigroup under `max`.
Instance details Defined in Data.Monoid.Inf Methods (<>) :: Inf Neg a -> Inf Neg a -> Inf Neg a Source # sconcat :: NonEmpty (Inf Neg a) -> Inf Neg a Source # stimes :: Integral b => b -> Inf Neg a -> Inf Neg a Source #
Ord a => Ord (Inf Neg a) Source # | Negative infinity is less than any finite value.
Instance details Defined in Data.Monoid.Inf Methods compare :: Inf Neg a -> Inf Neg a -> Ordering Source # (<) :: Inf Neg a -> Inf Neg a -> Bool Source # (<=) :: Inf Neg a -> Inf Neg a -> Bool Source # (>) :: Inf Neg a -> Inf Neg a -> Bool Source # (>=) :: Inf Neg a -> Inf Neg a -> Bool Source # max :: Inf Neg a -> Inf Neg a -> Inf Neg a Source # min :: Inf Neg a -> Inf Neg a -> Inf Neg a Source #

type PosInf a = Inf Pos a Source #

The type `a` extended with positive infinity.

type NegInf a = Inf Neg a Source #

The type `a` extended with negative infinity.

minimum :: Ord a => [a] -> PosInf a Source #

Find the minimum of a list of values. Returns positive infinity iff the list is empty.

maximum :: Ord a => [a] -> NegInf a Source #

Find the maximum of a list of values. Returns negative infinity iff the list is empty.

# Type-restricted constructors

posInfty :: PosInf a Source #

Positive infinity.

negInfty :: NegInf a Source #

Negative infinity.

posFinite :: a -> PosInf a Source #

Embed a finite value into the space of such values extended with positive infinity.

negFinite :: a -> NegInf a Source #

Embed a finite value into the space of such values extended with negative infinity.