{-# LANGUAGE LambdaCase      #-}
--------------------------------------------------------------------------------
-- |
-- Module      :  HGeometry.Unbounded
-- Copyright   :  (C) Frank Staals
-- License     :  see the LICENSE file
-- Maintainer  :  Frank Staals
--
-- Add an unbounded/infintity element to a data type. Essentially,
-- t'Bottom' adds \(-\infty\) (and is pretty much identical to Maybe),
-- whereas t'Top' adds \(\infty\). The 'UnBounded' type adds both.
--
--------------------------------------------------------------------------------
module HGeometry.Unbounded
  ( Top( ValT, Top), topToMaybe
  , _ValT, _Top, _TopMaybe

  , Bottom(Bottom, ValB), bottomToMaybe
  , _ValB, _Bottom, _BottomMaybe

  , UnBounded(..)
  , _Val
  , unBoundedToMaybe
  ) where

import           Control.Lens
import qualified Data.Foldable        as F
import           Data.Functor.Classes
import qualified Data.Traversable     as T

--------------------------------------------------------------------------------
-- * Top and Bottom

-- | @Top a@ represents the type a, together with a v'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
newtype Top a = GTop (Maybe a)
                deriving (Top a -> Top a -> Bool
(Top a -> Top a -> Bool) -> (Top a -> Top a -> Bool) -> Eq (Top a)
forall a. Eq a => Top a -> Top a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Top a -> Top a -> Bool
== :: Top a -> Top a -> Bool
$c/= :: forall a. Eq a => Top a -> Top a -> Bool
/= :: Top a -> Top a -> Bool
Eq,(forall a b. (a -> b) -> Top a -> Top b)
-> (forall a b. a -> Top b -> Top a) -> Functor Top
forall a b. a -> Top b -> Top a
forall a b. (a -> b) -> Top a -> Top b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Top a -> Top b
fmap :: forall a b. (a -> b) -> Top a -> Top b
$c<$ :: forall a b. a -> Top b -> Top a
<$ :: forall a b. a -> Top b -> Top a
Functor,(forall m. Monoid m => Top m -> m)
-> (forall m a. Monoid m => (a -> m) -> Top a -> m)
-> (forall m a. Monoid m => (a -> m) -> Top a -> m)
-> (forall a b. (a -> b -> b) -> b -> Top a -> b)
-> (forall a b. (a -> b -> b) -> b -> Top a -> b)
-> (forall b a. (b -> a -> b) -> b -> Top a -> b)
-> (forall b a. (b -> a -> b) -> b -> Top a -> b)
-> (forall a. (a -> a -> a) -> Top a -> a)
-> (forall a. (a -> a -> a) -> Top a -> a)
-> (forall a. Top a -> [a])
-> (forall a. Top a -> Bool)
-> (forall a. Top a -> Int)
-> (forall a. Eq a => a -> Top a -> Bool)
-> (forall a. Ord a => Top a -> a)
-> (forall a. Ord a => Top a -> a)
-> (forall a. Num a => Top a -> a)
-> (forall a. Num a => Top a -> a)
-> Foldable Top
forall a. Eq a => a -> Top a -> Bool
forall a. Num a => Top a -> a
forall a. Ord a => Top a -> a
forall m. Monoid m => Top m -> m
forall a. Top a -> Bool
forall a. Top a -> Int
forall a. Top a -> [a]
forall a. (a -> a -> a) -> Top a -> a
forall m a. Monoid m => (a -> m) -> Top a -> m
forall b a. (b -> a -> b) -> b -> Top a -> b
forall a b. (a -> b -> b) -> b -> Top a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Top m -> m
fold :: forall m. Monoid m => Top m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Top a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Top a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Top a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Top a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Top a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Top a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Top a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Top a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Top a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Top a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Top a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Top a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Top a -> a
foldr1 :: forall a. (a -> a -> a) -> Top a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Top a -> a
foldl1 :: forall a. (a -> a -> a) -> Top a -> a
$ctoList :: forall a. Top a -> [a]
toList :: forall a. Top a -> [a]
$cnull :: forall a. Top a -> Bool
null :: forall a. Top a -> Bool
$clength :: forall a. Top a -> Int
length :: forall a. Top a -> Int
$celem :: forall a. Eq a => a -> Top a -> Bool
elem :: forall a. Eq a => a -> Top a -> Bool
$cmaximum :: forall a. Ord a => Top a -> a
maximum :: forall a. Ord a => Top a -> a
$cminimum :: forall a. Ord a => Top a -> a
minimum :: forall a. Ord a => Top a -> a
$csum :: forall a. Num a => Top a -> a
sum :: forall a. Num a => Top a -> a
$cproduct :: forall a. Num a => Top a -> a
product :: forall a. Num a => Top a -> a
F.Foldable,Functor Top
Foldable Top
(Functor Top, Foldable Top) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Top a -> f (Top b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Top (f a) -> f (Top a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Top a -> m (Top b))
-> (forall (m :: * -> *) a. Monad m => Top (m a) -> m (Top a))
-> Traversable Top
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Top (m a) -> m (Top a)
forall (f :: * -> *) a. Applicative f => Top (f a) -> f (Top a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Top a -> m (Top b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Top a -> f (Top b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Top a -> f (Top b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Top a -> f (Top b)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Top (f a) -> f (Top a)
sequenceA :: forall (f :: * -> *) a. Applicative f => Top (f a) -> f (Top a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Top a -> m (Top b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Top a -> m (Top b)
$csequence :: forall (m :: * -> *) a. Monad m => Top (m a) -> m (Top a)
sequence :: forall (m :: * -> *) a. Monad m => Top (m a) -> m (Top a)
T.Traversable,Functor Top
Functor Top =>
(forall a. a -> Top a)
-> (forall a b. Top (a -> b) -> Top a -> Top b)
-> (forall a b c. (a -> b -> c) -> Top a -> Top b -> Top c)
-> (forall a b. Top a -> Top b -> Top b)
-> (forall a b. Top a -> Top b -> Top a)
-> Applicative Top
forall a. a -> Top a
forall a b. Top a -> Top b -> Top a
forall a b. Top a -> Top b -> Top b
forall a b. Top (a -> b) -> Top a -> Top b
forall a b c. (a -> b -> c) -> Top a -> Top b -> Top c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall a. a -> Top a
pure :: forall a. a -> Top a
$c<*> :: forall a b. Top (a -> b) -> Top a -> Top b
<*> :: forall a b. Top (a -> b) -> Top a -> Top b
$cliftA2 :: forall a b c. (a -> b -> c) -> Top a -> Top b -> Top c
liftA2 :: forall a b c. (a -> b -> c) -> Top a -> Top b -> Top c
$c*> :: forall a b. Top a -> Top b -> Top b
*> :: forall a b. Top a -> Top b -> Top b
$c<* :: forall a b. Top a -> Top b -> Top a
<* :: forall a b. Top a -> Top b -> Top a
Applicative,Applicative Top
Applicative Top =>
(forall a b. Top a -> (a -> Top b) -> Top b)
-> (forall a b. Top a -> Top b -> Top b)
-> (forall a. a -> Top a)
-> Monad Top
forall a. a -> Top a
forall a b. Top a -> Top b -> Top b
forall a b. Top a -> (a -> Top b) -> Top b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall a b. Top a -> (a -> Top b) -> Top b
>>= :: forall a b. Top a -> (a -> Top b) -> Top b
$c>> :: forall a b. Top a -> Top b -> Top b
>> :: forall a b. Top a -> Top b -> Top b
$creturn :: forall a. a -> Top a
return :: forall a. a -> Top a
Monad,(forall a. Eq a => Eq (Top a)) =>
(forall a b. (a -> b -> Bool) -> Top a -> Top b -> Bool) -> Eq1 Top
forall a. Eq a => Eq (Top a)
forall a b. (a -> b -> Bool) -> Top a -> Top b -> Bool
forall (f :: * -> *).
(forall a. Eq a => Eq (f a)) =>
(forall a b. (a -> b -> Bool) -> f a -> f b -> Bool) -> Eq1 f
$cliftEq :: forall a b. (a -> b -> Bool) -> Top a -> Top b -> Bool
liftEq :: forall a b. (a -> b -> Bool) -> Top a -> Top b -> Bool
Eq1)
                deriving newtype (NonEmpty (Top a) -> Top a
Top a -> Top a -> Top a
(Top a -> Top a -> Top a)
-> (NonEmpty (Top a) -> Top a)
-> (forall b. Integral b => b -> Top a -> Top a)
-> Semigroup (Top a)
forall b. Integral b => b -> Top a -> Top a
forall a. Semigroup a => NonEmpty (Top a) -> Top a
forall a. Semigroup a => Top a -> Top a -> Top a
forall a b. (Semigroup a, Integral b) => b -> Top a -> Top a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: forall a. Semigroup a => Top a -> Top a -> Top a
<> :: Top a -> Top a -> Top a
$csconcat :: forall a. Semigroup a => NonEmpty (Top a) -> Top a
sconcat :: NonEmpty (Top a) -> Top a
$cstimes :: forall a b. (Semigroup a, Integral b) => b -> Top a -> Top a
stimes :: forall b. Integral b => b -> Top a -> Top a
Semigroup,Semigroup (Top a)
Top a
Semigroup (Top a) =>
Top a
-> (Top a -> Top a -> Top a)
-> ([Top a] -> Top a)
-> Monoid (Top a)
[Top a] -> Top a
Top a -> Top a -> Top a
forall a. Semigroup a => Semigroup (Top a)
forall a. Semigroup a => Top a
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall a. Semigroup a => [Top a] -> Top a
forall a. Semigroup a => Top a -> Top a -> Top a
$cmempty :: forall a. Semigroup a => Top a
mempty :: Top a
$cmappend :: forall a. Semigroup a => Top a -> Top a -> Top a
mappend :: Top a -> Top a -> Top a
$cmconcat :: forall a. Semigroup a => [Top a] -> Top a
mconcat :: [Top a] -> Top a
Monoid)

-- | @Top a@ values are isomorphing to @Maybe a@ values.
topToMaybe :: Top a -> Maybe a
topToMaybe :: forall a. Top a -> Maybe a
topToMaybe (GTop Maybe a
mb) = Maybe a
mb

pattern ValT  :: a -> Top a
pattern $bValT :: forall a. a -> Top a
$mValT :: forall {r} {a}. Top a -> (a -> r) -> ((# #) -> r) -> r
ValT x = GTop (Just x)

pattern Top    :: Top a
pattern $bTop :: forall a. Top a
$mTop :: forall {r} {a}. Top a -> ((# #) -> r) -> ((# #) -> r) -> r
Top    = GTop Nothing

{-# COMPLETE ValT, Top #-}




instance Ord1 Top where
  liftCompare :: forall a b. (a -> b -> Ordering) -> Top a -> Top b -> Ordering
liftCompare a -> b -> Ordering
_   Top a
Top       Top b
Top     = Ordering
EQ
  liftCompare a -> b -> Ordering
_   Top a
_         Top b
Top     = Ordering
LT
  liftCompare a -> b -> Ordering
_   Top a
Top       Top b
_       = Ordering
GT
  liftCompare a -> b -> Ordering
cmp (ValT a
x) (ValT b
y) = a
x a -> b -> Ordering
`cmp` b
y

instance Ord a => Ord (Top a) where
  compare :: Top a -> Top a -> Ordering
compare = Top a -> Top a -> Ordering
forall (f :: * -> *) a. (Ord1 f, Ord a) => f a -> f a -> Ordering
compare1

instance Show a => Show (Top a) where
  show :: Top a -> String
show Top a
Top      = String
"Top"
  show (ValT a
x) = String
"ValT " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
x

-- | 'ValT' prism. Can be used to access the non-bottom element if it exists:
--
-- >>> ValT True & _ValT %~ not
-- ValT False
--
-- >>> Top & _ValT %~ not
-- Top
_ValT :: Prism (Top a) (Top b) a b
_ValT :: forall a b (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p a (f b) -> p (Top a) (f (Top b))
_ValT = (b -> Top b)
-> (Top a -> Either (Top b) a) -> Prism (Top a) (Top b) a b
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism b -> Top b
forall a. a -> Top a
ValT (\case Top a
Top -> Top b -> Either (Top b) a
forall a b. a -> Either a b
Left Top b
forall a. Top a
Top ; ValT a
x -> a -> Either (Top b) a
forall a b. b -> Either a b
Right a
x)

-- | t'Top' prism.
_Top :: Prism' (Top a) ()
_Top :: forall a (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p () (f ()) -> p (Top a) (f (Top a))
_Top = (() -> Top a) -> (Top a -> Maybe ()) -> Prism (Top a) (Top a) () ()
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (Top a -> () -> Top a
forall a b. a -> b -> a
const Top a
forall a. Top a
Top) (\case Top a
Top -> () -> Maybe ()
forall a. a -> Maybe a
Just () ; ValT a
_ -> Maybe ()
forall a. Maybe a
Nothing)

-- | Iso between a @Top a@ and a @Maybe a@, interpreting a v'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
_TopMaybe :: Iso' (Top a) (Maybe a)
_TopMaybe :: forall a (p :: * -> * -> *) (f :: * -> *).
(Profunctor p, Functor f) =>
p (Maybe a) (f (Maybe a)) -> p (Top a) (f (Top a))
_TopMaybe = (Top a -> Maybe a)
-> (Maybe a -> Top a) -> Iso (Top a) (Top a) (Maybe a) (Maybe a)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Top a -> Maybe a
forall a. Top a -> Maybe a
topToMaybe Maybe a -> Top a
forall a. Maybe a -> Top a
GTop

--------------------------------------------------------------------------------

-- | @`Bottom a`@ represents the type a, together with a v'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
newtype Bottom a = GBottom (Maybe a)
                 deriving (Bottom a -> Bottom a -> Bool
(Bottom a -> Bottom a -> Bool)
-> (Bottom a -> Bottom a -> Bool) -> Eq (Bottom a)
forall a. Eq a => Bottom a -> Bottom a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Bottom a -> Bottom a -> Bool
== :: Bottom a -> Bottom a -> Bool
$c/= :: forall a. Eq a => Bottom a -> Bottom a -> Bool
/= :: Bottom a -> Bottom a -> Bool
Eq,Eq (Bottom a)
Eq (Bottom a) =>
(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)
-> (Bottom a -> Bottom a -> Bottom a)
-> (Bottom a -> Bottom a -> Bottom a)
-> Ord (Bottom a)
Bottom a -> Bottom a -> Bool
Bottom a -> Bottom a -> Ordering
Bottom a -> Bottom a -> Bottom a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (Bottom a)
forall a. Ord a => Bottom a -> Bottom a -> Bool
forall a. Ord a => Bottom a -> Bottom a -> Ordering
forall a. Ord a => Bottom a -> Bottom a -> Bottom a
$ccompare :: forall a. Ord a => Bottom a -> Bottom a -> Ordering
compare :: Bottom a -> Bottom a -> Ordering
$c< :: forall a. Ord a => Bottom a -> Bottom a -> Bool
< :: Bottom a -> Bottom a -> Bool
$c<= :: forall a. Ord a => Bottom a -> Bottom a -> Bool
<= :: Bottom a -> Bottom a -> Bool
$c> :: forall a. Ord a => Bottom a -> Bottom a -> Bool
> :: Bottom a -> Bottom a -> Bool
$c>= :: forall a. Ord a => Bottom a -> Bottom a -> Bool
>= :: Bottom a -> Bottom a -> Bool
$cmax :: forall a. Ord a => Bottom a -> Bottom a -> Bottom a
max :: Bottom a -> Bottom a -> Bottom a
$cmin :: forall a. Ord a => Bottom a -> Bottom a -> Bottom a
min :: Bottom a -> Bottom a -> Bottom a
Ord,(forall a b. (a -> b) -> Bottom a -> Bottom b)
-> (forall a b. a -> Bottom b -> Bottom a) -> Functor Bottom
forall a b. a -> Bottom b -> Bottom a
forall a b. (a -> b) -> Bottom a -> Bottom b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Bottom a -> Bottom b
fmap :: forall a b. (a -> b) -> Bottom a -> Bottom b
$c<$ :: forall a b. a -> Bottom b -> Bottom a
<$ :: forall a b. a -> Bottom b -> Bottom a
Functor,(forall m. Monoid m => Bottom m -> m)
-> (forall m a. Monoid m => (a -> m) -> Bottom a -> m)
-> (forall m a. Monoid m => (a -> m) -> Bottom a -> m)
-> (forall a b. (a -> b -> b) -> b -> Bottom a -> b)
-> (forall a b. (a -> b -> b) -> b -> Bottom a -> b)
-> (forall b a. (b -> a -> b) -> b -> Bottom a -> b)
-> (forall b a. (b -> a -> b) -> b -> Bottom a -> b)
-> (forall a. (a -> a -> a) -> Bottom a -> a)
-> (forall a. (a -> a -> a) -> Bottom a -> a)
-> (forall a. Bottom a -> [a])
-> (forall a. Bottom a -> Bool)
-> (forall a. Bottom a -> Int)
-> (forall a. Eq a => a -> Bottom a -> Bool)
-> (forall a. Ord a => Bottom a -> a)
-> (forall a. Ord a => Bottom a -> a)
-> (forall a. Num a => Bottom a -> a)
-> (forall a. Num a => Bottom a -> a)
-> Foldable Bottom
forall a. Eq a => a -> Bottom a -> Bool
forall a. Num a => Bottom a -> a
forall a. Ord a => Bottom a -> a
forall m. Monoid m => Bottom m -> m
forall a. Bottom a -> Bool
forall a. Bottom a -> Int
forall a. Bottom a -> [a]
forall a. (a -> a -> a) -> Bottom a -> a
forall m a. Monoid m => (a -> m) -> Bottom a -> m
forall b a. (b -> a -> b) -> b -> Bottom a -> b
forall a b. (a -> b -> b) -> b -> Bottom a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Bottom m -> m
fold :: forall m. Monoid m => Bottom m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Bottom a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Bottom a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Bottom a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Bottom a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Bottom a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Bottom a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Bottom a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Bottom a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Bottom a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Bottom a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Bottom a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Bottom a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Bottom a -> a
foldr1 :: forall a. (a -> a -> a) -> Bottom a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Bottom a -> a
foldl1 :: forall a. (a -> a -> a) -> Bottom a -> a
$ctoList :: forall a. Bottom a -> [a]
toList :: forall a. Bottom a -> [a]
$cnull :: forall a. Bottom a -> Bool
null :: forall a. Bottom a -> Bool
$clength :: forall a. Bottom a -> Int
length :: forall a. Bottom a -> Int
$celem :: forall a. Eq a => a -> Bottom a -> Bool
elem :: forall a. Eq a => a -> Bottom a -> Bool
$cmaximum :: forall a. Ord a => Bottom a -> a
maximum :: forall a. Ord a => Bottom a -> a
$cminimum :: forall a. Ord a => Bottom a -> a
minimum :: forall a. Ord a => Bottom a -> a
$csum :: forall a. Num a => Bottom a -> a
sum :: forall a. Num a => Bottom a -> a
$cproduct :: forall a. Num a => Bottom a -> a
product :: forall a. Num a => Bottom a -> a
F.Foldable,Functor Bottom
Foldable Bottom
(Functor Bottom, Foldable Bottom) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Bottom a -> f (Bottom b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Bottom (f a) -> f (Bottom a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Bottom a -> m (Bottom b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Bottom (m a) -> m (Bottom a))
-> Traversable Bottom
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Bottom (m a) -> m (Bottom a)
forall (f :: * -> *) a.
Applicative f =>
Bottom (f a) -> f (Bottom a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bottom a -> m (Bottom b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Bottom a -> f (Bottom b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Bottom a -> f (Bottom b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Bottom a -> f (Bottom b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Bottom (f a) -> f (Bottom a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Bottom (f a) -> f (Bottom a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bottom a -> m (Bottom b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Bottom a -> m (Bottom b)
$csequence :: forall (m :: * -> *) a. Monad m => Bottom (m a) -> m (Bottom a)
sequence :: forall (m :: * -> *) a. Monad m => Bottom (m a) -> m (Bottom a)
T.Traversable,Functor Bottom
Functor Bottom =>
(forall a. a -> Bottom a)
-> (forall a b. Bottom (a -> b) -> Bottom a -> Bottom b)
-> (forall a b c.
    (a -> b -> c) -> Bottom a -> Bottom b -> Bottom c)
-> (forall a b. Bottom a -> Bottom b -> Bottom b)
-> (forall a b. Bottom a -> Bottom b -> Bottom a)
-> Applicative Bottom
forall a. a -> Bottom a
forall a b. Bottom a -> Bottom b -> Bottom a
forall a b. Bottom a -> Bottom b -> Bottom b
forall a b. Bottom (a -> b) -> Bottom a -> Bottom b
forall a b c. (a -> b -> c) -> Bottom a -> Bottom b -> Bottom c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall a. a -> Bottom a
pure :: forall a. a -> Bottom a
$c<*> :: forall a b. Bottom (a -> b) -> Bottom a -> Bottom b
<*> :: forall a b. Bottom (a -> b) -> Bottom a -> Bottom b
$cliftA2 :: forall a b c. (a -> b -> c) -> Bottom a -> Bottom b -> Bottom c
liftA2 :: forall a b c. (a -> b -> c) -> Bottom a -> Bottom b -> Bottom c
$c*> :: forall a b. Bottom a -> Bottom b -> Bottom b
*> :: forall a b. Bottom a -> Bottom b -> Bottom b
$c<* :: forall a b. Bottom a -> Bottom b -> Bottom a
<* :: forall a b. Bottom a -> Bottom b -> Bottom a
Applicative,Applicative Bottom
Applicative Bottom =>
(forall a b. Bottom a -> (a -> Bottom b) -> Bottom b)
-> (forall a b. Bottom a -> Bottom b -> Bottom b)
-> (forall a. a -> Bottom a)
-> Monad Bottom
forall a. a -> Bottom a
forall a b. Bottom a -> Bottom b -> Bottom b
forall a b. Bottom a -> (a -> Bottom b) -> Bottom b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall a b. Bottom a -> (a -> Bottom b) -> Bottom b
>>= :: forall a b. Bottom a -> (a -> Bottom b) -> Bottom b
$c>> :: forall a b. Bottom a -> Bottom b -> Bottom b
>> :: forall a b. Bottom a -> Bottom b -> Bottom b
$creturn :: forall a. a -> Bottom a
return :: forall a. a -> Bottom a
Monad,(forall a. Eq a => Eq (Bottom a)) =>
(forall a b. (a -> b -> Bool) -> Bottom a -> Bottom b -> Bool)
-> Eq1 Bottom
forall a. Eq a => Eq (Bottom a)
forall a b. (a -> b -> Bool) -> Bottom a -> Bottom b -> Bool
forall (f :: * -> *).
(forall a. Eq a => Eq (f a)) =>
(forall a b. (a -> b -> Bool) -> f a -> f b -> Bool) -> Eq1 f
$cliftEq :: forall a b. (a -> b -> Bool) -> Bottom a -> Bottom b -> Bool
liftEq :: forall a b. (a -> b -> Bool) -> Bottom a -> Bottom b -> Bool
Eq1,Eq1 Bottom
(Eq1 Bottom, forall a. Ord a => Ord (Bottom a)) =>
(forall a b.
 (a -> b -> Ordering) -> Bottom a -> Bottom b -> Ordering)
-> Ord1 Bottom
forall a. Ord a => Ord (Bottom a)
forall a b.
(a -> b -> Ordering) -> Bottom a -> Bottom b -> Ordering
forall (f :: * -> *).
(Eq1 f, forall a. Ord a => Ord (f a)) =>
(forall a b. (a -> b -> Ordering) -> f a -> f b -> Ordering)
-> Ord1 f
$cliftCompare :: forall a b.
(a -> b -> Ordering) -> Bottom a -> Bottom b -> Ordering
liftCompare :: forall a b.
(a -> b -> Ordering) -> Bottom a -> Bottom b -> Ordering
Ord1)
                 deriving newtype (NonEmpty (Bottom a) -> Bottom a
Bottom a -> Bottom a -> Bottom a
(Bottom a -> Bottom a -> Bottom a)
-> (NonEmpty (Bottom a) -> Bottom a)
-> (forall b. Integral b => b -> Bottom a -> Bottom a)
-> Semigroup (Bottom a)
forall b. Integral b => b -> Bottom a -> Bottom a
forall a. Semigroup a => NonEmpty (Bottom a) -> Bottom a
forall a. Semigroup a => Bottom a -> Bottom a -> Bottom a
forall a b. (Semigroup a, Integral b) => b -> Bottom a -> Bottom a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: forall a. Semigroup a => Bottom a -> Bottom a -> Bottom a
<> :: Bottom a -> Bottom a -> Bottom a
$csconcat :: forall a. Semigroup a => NonEmpty (Bottom a) -> Bottom a
sconcat :: NonEmpty (Bottom a) -> Bottom a
$cstimes :: forall a b. (Semigroup a, Integral b) => b -> Bottom a -> Bottom a
stimes :: forall b. Integral b => b -> Bottom a -> Bottom a
Semigroup,Semigroup (Bottom a)
Bottom a
Semigroup (Bottom a) =>
Bottom a
-> (Bottom a -> Bottom a -> Bottom a)
-> ([Bottom a] -> Bottom a)
-> Monoid (Bottom a)
[Bottom a] -> Bottom a
Bottom a -> Bottom a -> Bottom a
forall a. Semigroup a => Semigroup (Bottom a)
forall a. Semigroup a => Bottom a
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall a. Semigroup a => [Bottom a] -> Bottom a
forall a. Semigroup a => Bottom a -> Bottom a -> Bottom a
$cmempty :: forall a. Semigroup a => Bottom a
mempty :: Bottom a
$cmappend :: forall a. Semigroup a => Bottom a -> Bottom a -> Bottom a
mappend :: Bottom a -> Bottom a -> Bottom a
$cmconcat :: forall a. Semigroup a => [Bottom a] -> Bottom a
mconcat :: [Bottom a] -> Bottom a
Monoid)

-- | `Bottom a` values are isomorphing to `Maybe a` values.
bottomToMaybe :: Bottom a -> Maybe a
bottomToMaybe :: forall a. Bottom a -> Maybe a
bottomToMaybe (GBottom Maybe a
mb) = Maybe a
mb

pattern Bottom :: Bottom a
pattern $bBottom :: forall a. Bottom a
$mBottom :: forall {r} {a}. Bottom a -> ((# #) -> r) -> ((# #) -> r) -> r
Bottom = GBottom Nothing

pattern ValB   :: a -> Bottom a
pattern $bValB :: forall a. a -> Bottom a
$mValB :: forall {r} {a}. Bottom a -> (a -> r) -> ((# #) -> r) -> r
ValB x = GBottom (Just x)

{-# COMPLETE Bottom, ValB #-}

instance Show a => Show (Bottom a) where
  show :: Bottom a -> String
show Bottom a
Bottom   = String
"Bottom"
  show (ValB a
x) = String
"ValB " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
x

-- | 'ValB' prism. Can be used to access the non-bottom element if it exists:
--
-- >>> ValB True & _ValB %~ not
-- ValB False
--
-- >>> Bottom & _ValB %~ not
-- Bottom
_ValB :: Prism (Bottom a) (Bottom b) a b
_ValB :: forall a b (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p a (f b) -> p (Bottom a) (f (Bottom b))
_ValB = (b -> Bottom b)
-> (Bottom a -> Either (Bottom b) a)
-> Prism (Bottom a) (Bottom b) a b
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism b -> Bottom b
forall a. a -> Bottom a
ValB (\case Bottom a
Bottom -> Bottom b -> Either (Bottom b) a
forall a b. a -> Either a b
Left Bottom b
forall a. Bottom a
Bottom ; ValB a
x -> a -> Either (Bottom b) a
forall a b. b -> Either a b
Right a
x)

-- | t'Bottom' prism.
_Bottom :: Prism' (Bottom a) ()
_Bottom :: forall a (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p () (f ()) -> p (Bottom a) (f (Bottom a))
_Bottom = (() -> Bottom a)
-> (Bottom a -> Maybe ()) -> Prism (Bottom a) (Bottom a) () ()
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism' (Bottom a -> () -> Bottom a
forall a b. a -> b -> a
const Bottom a
forall a. Bottom a
Bottom) (\case Bottom a
Bottom -> () -> Maybe ()
forall a. a -> Maybe a
Just () ; ValB a
_ -> Maybe ()
forall a. Maybe a
Nothing)

-- | 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
_BottomMaybe :: Iso' (Bottom a) (Maybe a)
_BottomMaybe :: forall a (p :: * -> * -> *) (f :: * -> *).
(Profunctor p, Functor f) =>
p (Maybe a) (f (Maybe a)) -> p (Bottom a) (f (Bottom a))
_BottomMaybe = (Bottom a -> Maybe a)
-> (Maybe a -> Bottom a)
-> Iso (Bottom a) (Bottom a) (Maybe a) (Maybe a)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Bottom a -> Maybe a
forall a. Bottom a -> Maybe a
bottomToMaybe Maybe a -> Bottom a
forall a. Maybe a -> Bottom a
GBottom

--------------------------------------------------------------------------------

-- | `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.
data UnBounded a = MinInfinity | Val { forall a. UnBounded a -> a
_unUnBounded :: a }  | MaxInfinity
                 deriving (UnBounded a -> UnBounded a -> Bool
(UnBounded a -> UnBounded a -> Bool)
-> (UnBounded a -> UnBounded a -> Bool) -> Eq (UnBounded a)
forall a. Eq a => UnBounded a -> UnBounded a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => UnBounded a -> UnBounded a -> Bool
== :: UnBounded a -> UnBounded a -> Bool
$c/= :: forall a. Eq a => UnBounded a -> UnBounded a -> Bool
/= :: UnBounded a -> UnBounded a -> Bool
Eq,Eq (UnBounded a)
Eq (UnBounded a) =>
(UnBounded a -> UnBounded a -> Ordering)
-> (UnBounded a -> UnBounded a -> Bool)
-> (UnBounded a -> UnBounded a -> Bool)
-> (UnBounded a -> UnBounded a -> Bool)
-> (UnBounded a -> UnBounded a -> Bool)
-> (UnBounded a -> UnBounded a -> UnBounded a)
-> (UnBounded a -> UnBounded a -> UnBounded a)
-> Ord (UnBounded a)
UnBounded a -> UnBounded a -> Bool
UnBounded a -> UnBounded a -> Ordering
UnBounded a -> UnBounded a -> UnBounded a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (UnBounded a)
forall a. Ord a => UnBounded a -> UnBounded a -> Bool
forall a. Ord a => UnBounded a -> UnBounded a -> Ordering
forall a. Ord a => UnBounded a -> UnBounded a -> UnBounded a
$ccompare :: forall a. Ord a => UnBounded a -> UnBounded a -> Ordering
compare :: UnBounded a -> UnBounded a -> Ordering
$c< :: forall a. Ord a => UnBounded a -> UnBounded a -> Bool
< :: UnBounded a -> UnBounded a -> Bool
$c<= :: forall a. Ord a => UnBounded a -> UnBounded a -> Bool
<= :: UnBounded a -> UnBounded a -> Bool
$c> :: forall a. Ord a => UnBounded a -> UnBounded a -> Bool
> :: UnBounded a -> UnBounded a -> Bool
$c>= :: forall a. Ord a => UnBounded a -> UnBounded a -> Bool
>= :: UnBounded a -> UnBounded a -> Bool
$cmax :: forall a. Ord a => UnBounded a -> UnBounded a -> UnBounded a
max :: UnBounded a -> UnBounded a -> UnBounded a
$cmin :: forall a. Ord a => UnBounded a -> UnBounded a -> UnBounded a
min :: UnBounded a -> UnBounded a -> UnBounded a
Ord,(forall a b. (a -> b) -> UnBounded a -> UnBounded b)
-> (forall a b. a -> UnBounded b -> UnBounded a)
-> Functor UnBounded
forall a b. a -> UnBounded b -> UnBounded a
forall a b. (a -> b) -> UnBounded a -> UnBounded b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> UnBounded a -> UnBounded b
fmap :: forall a b. (a -> b) -> UnBounded a -> UnBounded b
$c<$ :: forall a b. a -> UnBounded b -> UnBounded a
<$ :: forall a b. a -> UnBounded b -> UnBounded a
Functor,(forall m. Monoid m => UnBounded m -> m)
-> (forall m a. Monoid m => (a -> m) -> UnBounded a -> m)
-> (forall m a. Monoid m => (a -> m) -> UnBounded a -> m)
-> (forall a b. (a -> b -> b) -> b -> UnBounded a -> b)
-> (forall a b. (a -> b -> b) -> b -> UnBounded a -> b)
-> (forall b a. (b -> a -> b) -> b -> UnBounded a -> b)
-> (forall b a. (b -> a -> b) -> b -> UnBounded a -> b)
-> (forall a. (a -> a -> a) -> UnBounded a -> a)
-> (forall a. (a -> a -> a) -> UnBounded a -> a)
-> (forall a. UnBounded a -> [a])
-> (forall a. UnBounded a -> Bool)
-> (forall a. UnBounded a -> Int)
-> (forall a. Eq a => a -> UnBounded a -> Bool)
-> (forall a. Ord a => UnBounded a -> a)
-> (forall a. Ord a => UnBounded a -> a)
-> (forall a. Num a => UnBounded a -> a)
-> (forall a. Num a => UnBounded a -> a)
-> Foldable UnBounded
forall a. Eq a => a -> UnBounded a -> Bool
forall a. Num a => UnBounded a -> a
forall a. Ord a => UnBounded a -> a
forall m. Monoid m => UnBounded m -> m
forall a. UnBounded a -> Bool
forall a. UnBounded a -> Int
forall a. UnBounded a -> [a]
forall a. (a -> a -> a) -> UnBounded a -> a
forall m a. Monoid m => (a -> m) -> UnBounded a -> m
forall b a. (b -> a -> b) -> b -> UnBounded a -> b
forall a b. (a -> b -> b) -> b -> UnBounded a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => UnBounded m -> m
fold :: forall m. Monoid m => UnBounded m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> UnBounded a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> UnBounded a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> UnBounded a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> UnBounded a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> UnBounded a -> b
foldr :: forall a b. (a -> b -> b) -> b -> UnBounded a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> UnBounded a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> UnBounded a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> UnBounded a -> b
foldl :: forall b a. (b -> a -> b) -> b -> UnBounded a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> UnBounded a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> UnBounded a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> UnBounded a -> a
foldr1 :: forall a. (a -> a -> a) -> UnBounded a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> UnBounded a -> a
foldl1 :: forall a. (a -> a -> a) -> UnBounded a -> a
$ctoList :: forall a. UnBounded a -> [a]
toList :: forall a. UnBounded a -> [a]
$cnull :: forall a. UnBounded a -> Bool
null :: forall a. UnBounded a -> Bool
$clength :: forall a. UnBounded a -> Int
length :: forall a. UnBounded a -> Int
$celem :: forall a. Eq a => a -> UnBounded a -> Bool
elem :: forall a. Eq a => a -> UnBounded a -> Bool
$cmaximum :: forall a. Ord a => UnBounded a -> a
maximum :: forall a. Ord a => UnBounded a -> a
$cminimum :: forall a. Ord a => UnBounded a -> a
minimum :: forall a. Ord a => UnBounded a -> a
$csum :: forall a. Num a => UnBounded a -> a
sum :: forall a. Num a => UnBounded a -> a
$cproduct :: forall a. Num a => UnBounded a -> a
product :: forall a. Num a => UnBounded a -> a
F.Foldable,Functor UnBounded
Foldable UnBounded
(Functor UnBounded, Foldable UnBounded) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> UnBounded a -> f (UnBounded b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    UnBounded (f a) -> f (UnBounded a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> UnBounded a -> m (UnBounded b))
-> (forall (m :: * -> *) a.
    Monad m =>
    UnBounded (m a) -> m (UnBounded a))
-> Traversable UnBounded
forall (t :: * -> *).
(Functor t, Foldable t) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
UnBounded (m a) -> m (UnBounded a)
forall (f :: * -> *) a.
Applicative f =>
UnBounded (f a) -> f (UnBounded a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> UnBounded a -> m (UnBounded b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> UnBounded a -> f (UnBounded b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> UnBounded a -> f (UnBounded b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> UnBounded a -> f (UnBounded b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
UnBounded (f a) -> f (UnBounded a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
UnBounded (f a) -> f (UnBounded a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> UnBounded a -> m (UnBounded b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> UnBounded a -> m (UnBounded b)
$csequence :: forall (m :: * -> *) a.
Monad m =>
UnBounded (m a) -> m (UnBounded a)
sequence :: forall (m :: * -> *) a.
Monad m =>
UnBounded (m a) -> m (UnBounded a)
T.Traversable)

-- | 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
_Val :: Prism (UnBounded a) (UnBounded b) a b
_Val :: forall a b (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p a (f b) -> p (UnBounded a) (f (UnBounded b))
_Val = (b -> UnBounded b)
-> (UnBounded a -> Either (UnBounded b) a)
-> Prism (UnBounded a) (UnBounded b) a b
forall b t s a. (b -> t) -> (s -> Either t a) -> Prism s t a b
prism b -> UnBounded b
forall a. a -> UnBounded a
Val UnBounded a -> Either (UnBounded b) a
forall {b} {a}. UnBounded b -> Either (UnBounded a) b
fromUnBounded
  where
    fromUnBounded :: UnBounded b -> Either (UnBounded a) b
fromUnBounded UnBounded b
MinInfinity = UnBounded a -> Either (UnBounded a) b
forall a b. a -> Either a b
Left UnBounded a
forall a. UnBounded a
MinInfinity
    fromUnBounded UnBounded b
MaxInfinity = UnBounded a -> Either (UnBounded a) b
forall a b. a -> Either a b
Left UnBounded a
forall a. UnBounded a
MaxInfinity
    fromUnBounded (Val b
v)     = b -> Either (UnBounded a) b
forall a b. b -> Either a b
Right b
v

instance Show a => Show (UnBounded a) where
  show :: UnBounded a -> String
show UnBounded a
MinInfinity = String
"MinInfinity"
  show (Val a
x)     = String
"Val " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
x
  show UnBounded a
MaxInfinity = String
"MaxInfinity"

instance Num a => Num (UnBounded a) where
  UnBounded a
MinInfinity + :: UnBounded a -> UnBounded a -> UnBounded a
+ UnBounded a
_           = UnBounded a
forall a. UnBounded a
MinInfinity
  UnBounded a
_           + UnBounded a
MinInfinity = UnBounded a
forall a. UnBounded a
MinInfinity
  (Val a
x)     + (Val a
y)     = a -> UnBounded a
forall a. a -> UnBounded a
Val (a -> UnBounded a) -> a -> UnBounded a
forall a b. (a -> b) -> a -> b
$ a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
y
  UnBounded a
_           + UnBounded a
MaxInfinity = UnBounded a
forall a. UnBounded a
MaxInfinity
  UnBounded a
MaxInfinity + UnBounded a
_           = UnBounded a
forall a. UnBounded a
MaxInfinity


  UnBounded a
MinInfinity * :: UnBounded a -> UnBounded a -> UnBounded a
* UnBounded a
_           = UnBounded a
forall a. UnBounded a
MinInfinity
  UnBounded a
_           * UnBounded a
MinInfinity = UnBounded a
forall a. UnBounded a
MinInfinity

  (Val a
x)     * (Val a
y)     = a -> UnBounded a
forall a. a -> UnBounded a
Val (a -> UnBounded a) -> a -> UnBounded a
forall a b. (a -> b) -> a -> b
$ a
x a -> a -> a
forall a. Num a => a -> a -> a
* a
y
  UnBounded a
_           * UnBounded a
MaxInfinity = UnBounded a
forall a. UnBounded a
MaxInfinity
  UnBounded a
MaxInfinity * UnBounded a
_           = UnBounded a
forall a. UnBounded a
MaxInfinity

  abs :: UnBounded a -> UnBounded a
abs UnBounded a
MinInfinity = UnBounded a
forall a. UnBounded a
MinInfinity
  abs (Val a
x)     = a -> UnBounded a
forall a. a -> UnBounded a
Val (a -> UnBounded a) -> a -> UnBounded a
forall a b. (a -> b) -> a -> b
$ a -> a
forall a. Num a => a -> a
abs a
x
  abs UnBounded a
MaxInfinity = UnBounded a
forall a. UnBounded a
MaxInfinity

  signum :: UnBounded a -> UnBounded a
signum UnBounded a
MinInfinity = -UnBounded a
1
  signum (Val a
x)     = a -> UnBounded a
forall a. a -> UnBounded a
Val (a -> UnBounded a) -> a -> UnBounded a
forall a b. (a -> b) -> a -> b
$ a -> a
forall a. Num a => a -> a
signum a
x
  signum UnBounded a
MaxInfinity = UnBounded a
1

  fromInteger :: Integer -> UnBounded a
fromInteger = a -> UnBounded a
forall a. a -> UnBounded a
Val (a -> UnBounded a) -> (Integer -> a) -> Integer -> UnBounded a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> a
forall a. Num a => Integer -> a
fromInteger

  negate :: UnBounded a -> UnBounded a
negate UnBounded a
MinInfinity = UnBounded a
forall a. UnBounded a
MaxInfinity
  negate (Val a
x)     = a -> UnBounded a
forall a. a -> UnBounded a
Val (a -> UnBounded a) -> a -> UnBounded a
forall a b. (a -> b) -> a -> b
$ a -> a
forall a. Num a => a -> a
negate a
x
  negate UnBounded a
MaxInfinity = UnBounded a
forall a. UnBounded a
MinInfinity

instance Fractional a => Fractional (UnBounded a) where
  UnBounded a
MinInfinity / :: UnBounded a -> UnBounded a -> UnBounded a
/ UnBounded a
_       = UnBounded a
forall a. UnBounded a
MinInfinity
  (Val a
x)     / (Val a
y) = a -> UnBounded a
forall a. a -> UnBounded a
Val (a -> UnBounded a) -> a -> UnBounded a
forall a b. (a -> b) -> a -> b
$ a
x a -> a -> a
forall a. Fractional a => a -> a -> a
/ a
y
  (Val a
_)     / UnBounded a
_       = UnBounded a
0
  UnBounded a
MaxInfinity / UnBounded a
_       = UnBounded a
forall a. UnBounded a
MaxInfinity

  fromRational :: Rational -> UnBounded a
fromRational = a -> UnBounded a
forall a. a -> UnBounded a
Val (a -> UnBounded a) -> (Rational -> a) -> Rational -> UnBounded a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> a
forall a. Fractional a => Rational -> a
fromRational

-- | Test if an Unbounded is actually bounded.
--
-- >>> unBoundedToMaybe (Val 5)
-- Just 5
-- >>> unBoundedToMaybe MinInfinity
-- Nothing
-- >>> unBoundedToMaybe MaxInfinity
-- Nothing
unBoundedToMaybe         :: UnBounded a -> Maybe a
unBoundedToMaybe :: forall a. UnBounded a -> Maybe a
unBoundedToMaybe (Val a
x) = a -> Maybe a
forall a. a -> Maybe a
Just a
x
unBoundedToMaybe UnBounded a
_       = Maybe a
forall a. Maybe a
Nothing