hgeometry-combinatorial
Copyright(C) Frank Staals
Licensesee the LICENSE file
MaintainerFrank Staals
Safe HaskellNone
LanguageGHC2021

HGeometry.Unbounded

Description

Add an unbounded/infintity element to a data type. Essentially, Bottom adds \(-\infty\) (and is pretty much identical to Maybe), whereas Top adds \(\infty\). The UnBounded type adds both.

Synopsis

Documentation

data Top a where Source #

Top a represents the type a, together with a Top element, i.e. an element that is greater than any other element. We can think of `Top a` being defined as:

>>> data Top a = ValT a | Top

Bundled Patterns

pattern ValT :: a -> Top a 
pattern Top :: Top a 

Instances

Instances details
Eq1 Top Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

liftEq :: (a -> b -> Bool) -> Top a -> Top b -> Bool #

Ord1 Top Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

liftCompare :: (a -> b -> Ordering) -> Top a -> Top b -> Ordering #

Applicative Top Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

pure :: a -> Top a #

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

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

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

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

Functor Top Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

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

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

Monad Top Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

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

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

return :: a -> Top a #

Foldable Top Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

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

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

foldMap' :: Monoid m => (a -> m) -> Top a -> m #

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

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

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

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

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

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

toList :: Top a -> [a] #

null :: Top a -> Bool #

length :: Top a -> Int #

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

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

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

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

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

Traversable Top Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

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

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

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

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

Semigroup a => Monoid (Top a) Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

mempty :: Top a #

mappend :: Top a -> Top a -> Top a #

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

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

Defined in HGeometry.Unbounded

Methods

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

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

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

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

Defined in HGeometry.Unbounded

Methods

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

show :: Top a -> String #

showList :: [Top a] -> ShowS #

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

Defined in HGeometry.Unbounded

Methods

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

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

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

Defined in HGeometry.Unbounded

Methods

compare :: Top a -> Top a -> Ordering #

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

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

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

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

max :: Top a -> Top a -> Top a #

min :: Top a -> Top a -> Top a #

topToMaybe :: Top a -> Maybe a Source #

Top a values are isomorphing to Maybe a values.

_ValT :: forall a b p f. (Choice p, Applicative f) => p a (f b) -> p (Top a) (f (Top b)) Source #

ValT prism. Can be used to access the non-bottom element if it exists:

>>> ValT True & _ValT %~ not
ValT False
>>> Top & _ValT %~ not
Top

_Top :: forall a p f. (Choice p, Applicative f) => p () (f ()) -> p (Top a) (f (Top a)) Source #

Top prism.

_TopMaybe :: forall a p f. (Profunctor p, Functor f) => p (Maybe a) (f (Maybe a)) -> p (Top a) (f (Top a)) Source #

Iso between a Top a and a Maybe a, interpreting a Top as a Nothing and vice versa. Note that this reverses the ordering of the elements.

>>> ValT 5 ^. _TopMaybe
Just 5
>>> Just 5 ^.re _TopMaybe
ValT 5
>>> Top ^. _TopMaybe
Nothing
>>> Nothing ^.re _TopMaybe
Top

data Bottom a where Source #

`Bottom a` represents the type a, together with a Bottom element, i.e. an element that is smaller than any other element. We can think of `Bottom a` being defined as:

>>> data Bottom a = Bottom | ValB a

Bundled Patterns

pattern Bottom :: Bottom a 
pattern ValB :: a -> Bottom a 

Instances

Instances details
Eq1 Bottom Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

liftEq :: (a -> b -> Bool) -> Bottom a -> Bottom b -> Bool #

Ord1 Bottom Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

liftCompare :: (a -> b -> Ordering) -> Bottom a -> Bottom b -> Ordering #

Applicative Bottom Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

pure :: a -> Bottom a #

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

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

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

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

Functor Bottom Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

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

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

Monad Bottom Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

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

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

return :: a -> Bottom a #

Foldable Bottom Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

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

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

foldMap' :: Monoid m => (a -> m) -> Bottom a -> m #

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

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

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

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

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

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

toList :: Bottom a -> [a] #

null :: Bottom a -> Bool #

length :: Bottom a -> Int #

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

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

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

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

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

Traversable Bottom Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

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

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

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

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

Semigroup a => Monoid (Bottom a) Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

mempty :: Bottom a #

mappend :: Bottom a -> Bottom a -> Bottom a #

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

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

Defined in HGeometry.Unbounded

Methods

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

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

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

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

Defined in HGeometry.Unbounded

Methods

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

show :: Bottom a -> String #

showList :: [Bottom a] -> ShowS #

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

Defined in HGeometry.Unbounded

Methods

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

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

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

Defined in HGeometry.Unbounded

Methods

compare :: Bottom a -> Bottom a -> Ordering #

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

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

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

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

max :: Bottom a -> Bottom a -> Bottom a #

min :: Bottom a -> Bottom a -> Bottom a #

bottomToMaybe :: Bottom a -> Maybe a Source #

`Bottom a` values are isomorphing to `Maybe a` values.

_ValB :: forall a b p f. (Choice p, Applicative f) => p a (f b) -> p (Bottom a) (f (Bottom b)) Source #

ValB prism. Can be used to access the non-bottom element if it exists:

>>> ValB True & _ValB %~ not
ValB False
>>> Bottom & _ValB %~ not
Bottom

_Bottom :: forall a p f. (Choice p, Applicative f) => p () (f ()) -> p (Bottom a) (f (Bottom a)) Source #

Bottom prism.

_BottomMaybe :: forall a p f. (Profunctor p, Functor f) => p (Maybe a) (f (Maybe a)) -> p (Bottom a) (f (Bottom a)) Source #

Iso between a 'Bottom a' and a 'Maybe a', interpreting a Bottom as a Nothing and vice versa.

>>> ValB 5 ^. _BottomMaybe
Just 5
>>> Just 5 ^.re _BottomMaybe
ValB 5
>>> Bottom ^. _BottomMaybe
Nothing
>>> Nothing ^.re _BottomMaybe
Bottom

data UnBounded a Source #

`UnBounded a` represents the type a, together with an element MaxInfinity larger than any other element, and an element MinInfinity, smaller than any other element.

Constructors

MinInfinity 
Val 

Fields

MaxInfinity 

Instances

Instances details
Functor UnBounded Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

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

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

Foldable UnBounded Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

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

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

foldMap' :: Monoid m => (a -> m) -> UnBounded a -> m #

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

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

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

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

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

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

toList :: UnBounded a -> [a] #

null :: UnBounded a -> Bool #

length :: UnBounded a -> Int #

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

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

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

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

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

Traversable UnBounded Source # 
Instance details

Defined in HGeometry.Unbounded

Methods

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

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

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

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

Num a => Num (UnBounded a) Source # 
Instance details

Defined in HGeometry.Unbounded

Fractional a => Fractional (UnBounded a) Source # 
Instance details

Defined in HGeometry.Unbounded

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

Defined in HGeometry.Unbounded

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

Defined in HGeometry.Unbounded

Methods

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

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

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

Defined in HGeometry.Unbounded

_Val :: forall a b p f. (Choice p, Applicative f) => p a (f b) -> p (UnBounded a) (f (UnBounded b)) Source #

Prism to access unbounded value if it exists.

>>> Val True ^? _Val
Just True
>>> MinInfinity ^? _Val :: Maybe Bool
Nothing
>>> Val True & _Val %~ not
Val False
>>> MaxInfinity & _Val %~ not
MaxInfinity

unBoundedToMaybe :: UnBounded a -> Maybe a Source #

Test if an Unbounded is actually bounded.

>>> unBoundedToMaybe (Val 5)
Just 5
>>> unBoundedToMaybe MinInfinity
Nothing
>>> unBoundedToMaybe MaxInfinity
Nothing