| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Natural
Synopsis
- data Natural
- class HasNatural a where
- class AsNatural a where
- newtype ProductNatural = ProductNatural Natural
- newtype MaxNatural = MaxNatural Natural
- newtype MinNatural = MinNatural Natural
- zero :: Prism' Natural ()
- zero' :: Natural
- successor :: Prism' Natural Natural
- successor' :: Natural -> Natural
- plus :: Natural -> Natural -> Natural
- multiply :: Natural -> Natural -> Natural
- power :: Natural -> Natural -> Natural
- zeroOr :: AsNatural a => a -> Natural
- length :: Foldable f => f a -> Natural
- replicate :: Natural -> a -> [a]
- take :: Natural -> [a] -> [a]
- drop :: Natural -> [a] -> [a]
- splitAt :: Natural -> [a] -> ([a], [a])
- (!!) :: [a] -> Natural -> Maybe a
- findIndices :: (a -> Bool) -> [a] -> [Natural]
- findIndex :: (a -> Bool) -> [a] -> Maybe Natural
- elemIndices :: Eq a => a -> [a] -> [Natural]
- elemIndex :: Eq a => a -> [a] -> Maybe Natural
- minus :: Natural -> Natural -> Natural
- list :: Iso' Natural [()]
- data Positive
- class HasPositive a where
- class AsPositive a where
- newtype SumPositive = SumPositive Positive
- newtype MaxPositive = MaxPositive Positive
- newtype MinPositive = MinPositive Positive
- naturalPositive :: Iso' Natural (Maybe Positive)
- one :: Prism' Positive ()
- one' :: Positive
- successor1 :: Prism' Positive Positive
- successor1' :: Positive -> Positive
- successorW :: Iso' Natural Positive
- plus1 :: Positive -> Positive -> Positive
- multiply1 :: Positive -> Positive -> Positive
- power1 :: Positive -> Positive -> Positive
- oneOr :: AsPositive a => a -> Positive
- length1 :: Foldable1 f => f a -> Positive
- replicate1 :: Positive -> a -> NonEmpty a
- take1 :: Positive -> NonEmpty a -> NonEmpty a
- drop1 :: Positive -> NonEmpty a -> [a]
- splitAt1 :: Positive -> NonEmpty a -> (NonEmpty a, [a])
- (!!!) :: NonEmpty a -> Positive -> Maybe a
- findIndices1 :: (a -> Bool) -> NonEmpty a -> [Positive]
- findIndex1 :: (a -> Bool) -> NonEmpty a -> Maybe Positive
- elemIndices1 :: Eq a => a -> NonEmpty a -> [Positive]
- elemIndex1 :: Eq a => a -> NonEmpty a -> Maybe Positive
- minus1 :: Positive -> Positive -> Positive
- list1 :: Iso' Positive (NonEmpty ())
- plusone :: Natural -> Positive
- minusone :: Positive -> Natural
- data NotZero = NotZero Bool Positive
- class HasNotZero a where
- class AsNotZero a where
- newtype SumNotZero = SumNotZero NotZero
- newtype MaxNotZero = MaxNotZero NotZero
- newtype MinNotZero = MinNotZero NotZero
- positiveNotZero :: Positive -> NotZero
- negativeNotZero :: Positive -> NotZero
- notZeroPositive :: NotZero -> Positive
- notZeroInteger :: NotZero -> Integer
- isPositive :: NotZero -> Bool
- isNegative :: NotZero -> Bool
- negateNZ :: NotZero -> NotZero
- absoluteNZ :: NotZero -> Positive
- signumNZ :: NotZero -> NotZero
- plusNZ :: NotZero -> NotZero -> Maybe NotZero
- multiplyNZ :: NotZero -> NotZero -> NotZero
- notZeroOr :: AsNotZero a => a -> NotZero
- toJsonNatural :: HasNatural a => a -> Value
- parseJsonNatural :: Value -> Parser Natural
- toJsonPositive :: HasPositive a => a -> Value
- parseJsonPositive :: Value -> Parser Positive
- toJsonNotZero :: HasNotZero a => a -> Value
- parseJsonNotZero :: Value -> Parser NotZero
Documentation
A natural number (>= 0) represented as a newtype over Integer.
>>>nat 0Natural 0
>>>nat 5Natural 5
Instances
| FromJSON Natural Source # | Parses a
|
| ToJSON Natural Source # | Serialises a
|
| Monoid Natural Source # |
|
| Semigroup Natural Source # |
|
| Show Natural Source # | |
| Eq Natural Source # | |
| Ord Natural Source # | |
| AsNatural Natural Source # |
|
| AsPositive Natural Source # |
|
| HasNatural Natural Source # |
|
class HasNatural a where Source #
Instances
| HasNatural MaxNatural Source # |
|
| HasNatural MinNatural Source # |
|
| HasNatural Natural Source # |
|
| HasNatural ProductNatural Source # |
|
class AsNatural a where Source #
Instances
| AsNatural MaxNatural Source # |
|
| AsNatural MinNatural Source # |
|
| AsNatural Natural Source # |
|
| AsNatural ProductNatural Source # |
|
| AsNatural Integer Source # |
|
| AsNatural Int Source # |
|
| AsNatural Word Source # |
|
| Integral a => AsNatural (Identity a) Source # |
|
| Integral a => AsNatural (Const a b) Source # |
|
newtype ProductNatural Source #
>>>ProductNatural (nat 3) <> ProductNatural (nat 4)ProductNatural (Natural 12)
>>>mempty :: ProductNaturalProductNatural (Natural 1)
Constructors
| ProductNatural Natural |
Instances
newtype MaxNatural Source #
>>>MaxNatural (nat 3) <> MaxNatural (nat 7)MaxNatural (Natural 7)
Constructors
| MaxNatural Natural |
Instances
| FromJSON MaxNatural Source # | Parses a
|
Defined in Natural | |
| ToJSON MaxNatural Source # | Serialises a
|
Defined in Natural Methods toJSON :: MaxNatural -> Value # toEncoding :: MaxNatural -> Encoding # toJSONList :: [MaxNatural] -> Value # toEncodingList :: [MaxNatural] -> Encoding # omitField :: MaxNatural -> Bool # | |
| Semigroup MaxNatural Source # |
|
Defined in Natural Methods (<>) :: MaxNatural -> MaxNatural -> MaxNatural # sconcat :: NonEmpty MaxNatural -> MaxNatural # stimes :: Integral b => b -> MaxNatural -> MaxNatural # | |
| Show MaxNatural Source # | |
Defined in Natural Methods showsPrec :: Int -> MaxNatural -> ShowS # show :: MaxNatural -> String # showList :: [MaxNatural] -> ShowS # | |
| Eq MaxNatural Source # | |
Defined in Natural | |
| Ord MaxNatural Source # | |
Defined in Natural Methods compare :: MaxNatural -> MaxNatural -> Ordering # (<) :: MaxNatural -> MaxNatural -> Bool # (<=) :: MaxNatural -> MaxNatural -> Bool # (>) :: MaxNatural -> MaxNatural -> Bool # (>=) :: MaxNatural -> MaxNatural -> Bool # max :: MaxNatural -> MaxNatural -> MaxNatural # min :: MaxNatural -> MaxNatural -> MaxNatural # | |
| Wrapped MaxNatural Source # |
|
| AsNatural MaxNatural Source # |
|
| HasNatural MaxNatural Source # |
|
| MaxNatural ~ a => Rewrapped MaxNatural a Source # | |
Defined in Natural | |
| type Unwrapped MaxNatural Source # | |
Defined in Natural | |
newtype MinNatural Source #
>>>MinNatural (nat 3) <> MinNatural (nat 7)MinNatural (Natural 3)
Constructors
| MinNatural Natural |
Instances
| FromJSON MinNatural Source # | Parses a
|
Defined in Natural | |
| ToJSON MinNatural Source # | Serialises a
|
Defined in Natural Methods toJSON :: MinNatural -> Value # toEncoding :: MinNatural -> Encoding # toJSONList :: [MinNatural] -> Value # toEncodingList :: [MinNatural] -> Encoding # omitField :: MinNatural -> Bool # | |
| Semigroup MinNatural Source # |
|
Defined in Natural Methods (<>) :: MinNatural -> MinNatural -> MinNatural # sconcat :: NonEmpty MinNatural -> MinNatural # stimes :: Integral b => b -> MinNatural -> MinNatural # | |
| Show MinNatural Source # | |
Defined in Natural Methods showsPrec :: Int -> MinNatural -> ShowS # show :: MinNatural -> String # showList :: [MinNatural] -> ShowS # | |
| Eq MinNatural Source # | |
Defined in Natural | |
| Ord MinNatural Source # | |
Defined in Natural Methods compare :: MinNatural -> MinNatural -> Ordering # (<) :: MinNatural -> MinNatural -> Bool # (<=) :: MinNatural -> MinNatural -> Bool # (>) :: MinNatural -> MinNatural -> Bool # (>=) :: MinNatural -> MinNatural -> Bool # max :: MinNatural -> MinNatural -> MinNatural # min :: MinNatural -> MinNatural -> MinNatural # | |
| Wrapped MinNatural Source # |
|
| AsNatural MinNatural Source # |
|
| HasNatural MinNatural Source # |
|
| MinNatural ~ a => Rewrapped MinNatural a Source # | |
Defined in Natural | |
| type Unwrapped MinNatural Source # | |
Defined in Natural | |
zero :: Prism' Natural () Source #
Prism matching zero.
>>>zero # ()Natural 0
>>>nat 0 ^? zeroJust ()
>>>nat 3 ^? zeroNothing
successor :: Prism' Natural Natural Source #
Prism between a natural and its predecessor.
>>>successor # nat 0Natural 1
>>>successor # nat 4Natural 5
>>>nat 5 ^? successorJust (Natural 4)
>>>nat 0 ^? successorNothing
successor' :: Natural -> Natural Source #
The successor of a natural number.
>>>successor' (nat 0)Natural 1
>>>successor' (nat 4)Natural 5
plus :: Natural -> Natural -> Natural Source #
Add two natural numbers.
>>>plus (nat 3) (nat 4)Natural 7
>>>plus (nat 0) (nat 5)Natural 5
multiply :: Natural -> Natural -> Natural Source #
Multiply two natural numbers.
>>>multiply (nat 3) (nat 4)Natural 12
>>>multiply (nat 0) (nat 5)Natural 0
power :: Natural -> Natural -> Natural Source #
Raise a natural to a natural power.
>>>power (nat 2) (nat 10)Natural 1024
>>>power (nat 3) (nat 0)Natural 1
zeroOr :: AsNatural a => a -> Natural Source #
Return the natural if the prism matches, otherwise zero.
>>>zeroOr (5 :: Integer)Natural 5
>>>zeroOr (-1 :: Integer)Natural 0
length :: Foldable f => f a -> Natural Source #
Count the elements in a foldable structure.
>>>length [1,2,3 :: Int]Natural 3
>>>length ([] :: [Int])Natural 0
replicate :: Natural -> a -> [a] Source #
Replicate a value a natural number of times.
>>>replicate (nat 3) 'x'"xxx"
>>>replicate (nat 0) 'x'""
take :: Natural -> [a] -> [a] Source #
Take the first n elements.
>>>take (nat 2) [1,2,3,4,5 :: Int][1,2]
>>>take (nat 0) [1,2,3 :: Int][]
>>>take (nat 5) [1,2 :: Int][1,2]
drop :: Natural -> [a] -> [a] Source #
Drop the first n elements.
>>>drop (nat 2) [1,2,3,4,5 :: Int][3,4,5]
>>>drop (nat 0) [1,2,3 :: Int][1,2,3]
>>>drop (nat 5) [1,2 :: Int][]
splitAt :: Natural -> [a] -> ([a], [a]) Source #
Split a list at position n.
>>>splitAt (nat 2) [1,2,3,4,5 :: Int]([1,2],[3,4,5])
(!!) :: [a] -> Natural -> Maybe a Source #
Index into a list.
>>>[10,20,30 :: Int] !! nat 0Just 10
>>>[10,20,30 :: Int] !! nat 2Just 30
>>>[10,20,30 :: Int] !! nat 5Nothing
>>>([] :: [Int]) !! nat 0Nothing
findIndices :: (a -> Bool) -> [a] -> [Natural] Source #
Find all indices where the predicate holds.
>>>findIndices (== 'a') "abacad"[Natural 0,Natural 2,Natural 4]
>>>findIndices (== 'z') "abacad"[]
findIndex :: (a -> Bool) -> [a] -> Maybe Natural Source #
Find the first index where the predicate holds.
>>>findIndex (== 'c') "abcde"Just (Natural 2)
>>>findIndex (== 'z') "abcde"Nothing
elemIndices :: Eq a => a -> [a] -> [Natural] Source #
Find all indices of a given element.
>>>elemIndices 'a' "banana"[Natural 1,Natural 3,Natural 5]
elemIndex :: Eq a => a -> [a] -> Maybe Natural Source #
Find the first index of a given element.
>>>elemIndex 'n' "banana"Just (Natural 2)
>>>elemIndex 'z' "banana"Nothing
minus :: Natural -> Natural -> Natural Source #
Subtract two naturals, flooring at zero.
>>>minus (nat 5) (nat 3)Natural 2
>>>minus (nat 3) (nat 5)Natural 0
>>>minus (nat 3) (nat 3)Natural 0
list :: Iso' Natural [()] Source #
Iso between a natural and a list of units.
>>>nat 3 ^. list[(),(),()]
>>>length (nat 3 ^. list)Natural 3
A positive integer (>= 1). Semigroup is multiplication.
>>>pos 3Positive 3
>>>pos 3 <> pos 4Positive 12
Instances
| FromJSON Positive Source # | Parses a
|
| ToJSON Positive Source # | Serialises a
|
| Semigroup Positive Source # |
|
| Show Positive Source # | |
| Eq Positive Source # | |
| Ord Positive Source # | |
Defined in Natural | |
| AsPositive Positive Source # |
|
| HasPositive Positive Source # |
|
class HasPositive a where Source #
Instances
| HasPositive MaxPositive Source # |
|
| HasPositive MinPositive Source # |
|
| HasPositive Positive Source # |
|
| HasPositive SumPositive Source # |
|
class AsPositive a where Source #
Instances
| AsPositive MaxPositive Source # |
|
| AsPositive MinPositive Source # |
|
| AsPositive Natural Source # |
|
| AsPositive NotZero Source # | Prism from
|
| AsPositive Positive Source # |
|
| AsPositive SumPositive Source # |
|
| AsPositive Integer Source # |
|
| AsPositive Int Source # |
|
| AsPositive Word Source # |
|
| Integral a => AsPositive (Identity a) Source # |
|
| Integral a => AsPositive (Const a b) Source # |
|
newtype SumPositive Source #
>>>SumPositive (pos 3) <> SumPositive (pos 4)SumPositive (Positive 7)
Constructors
| SumPositive Positive |
Instances
| FromJSON SumPositive Source # | Parses a
|
Defined in Natural | |
| ToJSON SumPositive Source # | Serialises a
|
Defined in Natural Methods toJSON :: SumPositive -> Value # toEncoding :: SumPositive -> Encoding # toJSONList :: [SumPositive] -> Value # toEncodingList :: [SumPositive] -> Encoding # omitField :: SumPositive -> Bool # | |
| Semigroup SumPositive Source # |
|
Defined in Natural Methods (<>) :: SumPositive -> SumPositive -> SumPositive # sconcat :: NonEmpty SumPositive -> SumPositive # stimes :: Integral b => b -> SumPositive -> SumPositive # | |
| Show SumPositive Source # | |
Defined in Natural Methods showsPrec :: Int -> SumPositive -> ShowS # show :: SumPositive -> String # showList :: [SumPositive] -> ShowS # | |
| Eq SumPositive Source # | |
Defined in Natural | |
| Ord SumPositive Source # | |
Defined in Natural Methods compare :: SumPositive -> SumPositive -> Ordering # (<) :: SumPositive -> SumPositive -> Bool # (<=) :: SumPositive -> SumPositive -> Bool # (>) :: SumPositive -> SumPositive -> Bool # (>=) :: SumPositive -> SumPositive -> Bool # max :: SumPositive -> SumPositive -> SumPositive # min :: SumPositive -> SumPositive -> SumPositive # | |
| Wrapped SumPositive Source # |
|
| AsPositive SumPositive Source # |
|
| HasPositive SumPositive Source # |
|
| SumPositive ~ a => Rewrapped SumPositive a Source # | |
Defined in Natural | |
| type Unwrapped SumPositive Source # | |
Defined in Natural | |
newtype MaxPositive Source #
>>>MaxPositive (pos 3) <> MaxPositive (pos 7)MaxPositive (Positive 7)
Constructors
| MaxPositive Positive |
Instances
| FromJSON MaxPositive Source # | Parses a
|
Defined in Natural | |
| ToJSON MaxPositive Source # | Serialises a
|
Defined in Natural Methods toJSON :: MaxPositive -> Value # toEncoding :: MaxPositive -> Encoding # toJSONList :: [MaxPositive] -> Value # toEncodingList :: [MaxPositive] -> Encoding # omitField :: MaxPositive -> Bool # | |
| Semigroup MaxPositive Source # |
|
Defined in Natural Methods (<>) :: MaxPositive -> MaxPositive -> MaxPositive # sconcat :: NonEmpty MaxPositive -> MaxPositive # stimes :: Integral b => b -> MaxPositive -> MaxPositive # | |
| Show MaxPositive Source # | |
Defined in Natural Methods showsPrec :: Int -> MaxPositive -> ShowS # show :: MaxPositive -> String # showList :: [MaxPositive] -> ShowS # | |
| Eq MaxPositive Source # | |
Defined in Natural | |
| Ord MaxPositive Source # | |
Defined in Natural Methods compare :: MaxPositive -> MaxPositive -> Ordering # (<) :: MaxPositive -> MaxPositive -> Bool # (<=) :: MaxPositive -> MaxPositive -> Bool # (>) :: MaxPositive -> MaxPositive -> Bool # (>=) :: MaxPositive -> MaxPositive -> Bool # max :: MaxPositive -> MaxPositive -> MaxPositive # min :: MaxPositive -> MaxPositive -> MaxPositive # | |
| Wrapped MaxPositive Source # |
|
| AsPositive MaxPositive Source # |
|
| HasPositive MaxPositive Source # |
|
| MaxPositive ~ a => Rewrapped MaxPositive a Source # | |
Defined in Natural | |
| type Unwrapped MaxPositive Source # | |
Defined in Natural | |
newtype MinPositive Source #
>>>MinPositive (pos 3) <> MinPositive (pos 7)MinPositive (Positive 3)
Constructors
| MinPositive Positive |
Instances
| FromJSON MinPositive Source # | Parses a
|
Defined in Natural | |
| ToJSON MinPositive Source # | Serialises a
|
Defined in Natural Methods toJSON :: MinPositive -> Value # toEncoding :: MinPositive -> Encoding # toJSONList :: [MinPositive] -> Value # toEncodingList :: [MinPositive] -> Encoding # omitField :: MinPositive -> Bool # | |
| Semigroup MinPositive Source # |
|
Defined in Natural Methods (<>) :: MinPositive -> MinPositive -> MinPositive # sconcat :: NonEmpty MinPositive -> MinPositive # stimes :: Integral b => b -> MinPositive -> MinPositive # | |
| Show MinPositive Source # | |
Defined in Natural Methods showsPrec :: Int -> MinPositive -> ShowS # show :: MinPositive -> String # showList :: [MinPositive] -> ShowS # | |
| Eq MinPositive Source # | |
Defined in Natural | |
| Ord MinPositive Source # | |
Defined in Natural Methods compare :: MinPositive -> MinPositive -> Ordering # (<) :: MinPositive -> MinPositive -> Bool # (<=) :: MinPositive -> MinPositive -> Bool # (>) :: MinPositive -> MinPositive -> Bool # (>=) :: MinPositive -> MinPositive -> Bool # max :: MinPositive -> MinPositive -> MinPositive # min :: MinPositive -> MinPositive -> MinPositive # | |
| Wrapped MinPositive Source # |
|
| AsPositive MinPositive Source # |
|
| HasPositive MinPositive Source # |
|
| MinPositive ~ a => Rewrapped MinPositive a Source # | |
Defined in Natural | |
| type Unwrapped MinPositive Source # | |
Defined in Natural | |
naturalPositive :: Iso' Natural (Maybe Positive) Source #
Iso between a natural and maybe a positive.
>>>nat 5 ^. naturalPositiveJust (Positive 5)
>>>nat 0 ^. naturalPositiveNothing
one :: Prism' Positive () Source #
Prism matching one.
>>>one # ()Positive 1
>>>pos 1 ^? oneJust ()
>>>pos 3 ^? oneNothing
successor1 :: Prism' Positive Positive Source #
Prism between a positive and its predecessor.
>>>successor1 # pos 1Positive 2
>>>successor1 # pos 4Positive 5
>>>pos 5 ^? successor1Just (Positive 4)
>>>pos 1 ^? successor1Nothing
successor1' :: Positive -> Positive Source #
The successor of a positive number.
>>>successor1' (pos 1)Positive 2
>>>successor1' (pos 4)Positive 5
successorW :: Iso' Natural Positive Source #
Iso between natural and positive (n - n+1).
>>>nat 0 ^. successorWPositive 1
>>>nat 4 ^. successorWPositive 5
>>>successorW # pos 1Natural 0
>>>successorW # pos 5Natural 4
plus1 :: Positive -> Positive -> Positive Source #
Add two positive numbers.
>>>plus1 (pos 3) (pos 4)Positive 7
multiply1 :: Positive -> Positive -> Positive Source #
Multiply two positive numbers.
>>>multiply1 (pos 3) (pos 4)Positive 12
power1 :: Positive -> Positive -> Positive Source #
Raise a positive to a positive power.
>>>power1 (pos 2) (pos 10)Positive 1024
>>>power1 (pos 3) (pos 2)Positive 9
oneOr :: AsPositive a => a -> Positive Source #
Return the positive if the prism matches, otherwise one.
>>>oneOr (5 :: Integer)Positive 5
>>>oneOr (0 :: Integer)Positive 1
length1 :: Foldable1 f => f a -> Positive Source #
Count the elements in a non-empty foldable.
>>>length1 ('a' :| "bc")Positive 3
>>>length1 ('x' :| "")Positive 1
replicate1 :: Positive -> a -> NonEmpty a Source #
Replicate a value a positive number of times.
>>>replicate1 (pos 3) 'x''x' :| "xx"
>>>replicate1 (pos 1) 'y''y' :| ""
take1 :: Positive -> NonEmpty a -> NonEmpty a Source #
Take the first n elements from a non-empty list.
>>>take1 (pos 2) (1 :| [2,3,4,5 :: Int])1 :| [2]
>>>take1 (pos 1) (1 :| [2,3 :: Int])1 :| []
drop1 :: Positive -> NonEmpty a -> [a] Source #
Drop the first n elements from a non-empty list.
>>>drop1 (pos 2) (1 :| [2,3,4,5 :: Int])[3,4,5]
>>>drop1 (pos 1) (1 :| [2,3 :: Int])[2,3]
splitAt1 :: Positive -> NonEmpty a -> (NonEmpty a, [a]) Source #
Split a non-empty list at position n.
>>>splitAt1 (pos 2) (1 :| [2,3,4,5 :: Int])(1 :| [2],[3,4,5])
(!!!) :: NonEmpty a -> Positive -> Maybe a Source #
Index into a non-empty list (1-based).
>>>(10 :| [20,30 :: Int]) !!! pos 1Just 10
>>>(10 :| [20,30 :: Int]) !!! pos 3Just 30
>>>(10 :| [20,30 :: Int]) !!! pos 5Nothing
findIndices1 :: (a -> Bool) -> NonEmpty a -> [Positive] Source #
Find all 1-based indices where the predicate holds.
>>>findIndices1 (== 'a') ('a' :| "baca")[Positive 1,Positive 3,Positive 5]
findIndex1 :: (a -> Bool) -> NonEmpty a -> Maybe Positive Source #
Find the first 1-based index where the predicate holds.
>>>findIndex1 (== 'c') ('a' :| "bcde")Just (Positive 3)
>>>findIndex1 (== 'z') ('a' :| "bcde")Nothing
elemIndices1 :: Eq a => a -> NonEmpty a -> [Positive] Source #
Find all 1-based indices of a given element.
>>>elemIndices1 'a' ('b' :| "anana")[Positive 2,Positive 4,Positive 6]
elemIndex1 :: Eq a => a -> NonEmpty a -> Maybe Positive Source #
Find the first 1-based index of a given element.
>>>elemIndex1 'n' ('b' :| "anana")Just (Positive 3)
>>>elemIndex1 'z' ('b' :| "anana")Nothing
minus1 :: Positive -> Positive -> Positive Source #
Subtract two positives, flooring at one.
>>>minus1 (pos 5) (pos 3)Positive 2
>>>minus1 (pos 3) (pos 5)Positive 1
>>>minus1 (pos 3) (pos 3)Positive 1
list1 :: Iso' Positive (NonEmpty ()) Source #
Iso between a positive and a non-empty list of units.
>>>pos 3 ^. list1() :| [(),()]
>>>length1 (pos 3 ^. list1)Positive 3
plusone :: Natural -> Positive Source #
Convert natural to positive by adding one.
>>>plusone (nat 0)Positive 1
>>>plusone (nat 4)Positive 5
minusone :: Positive -> Natural Source #
Convert positive to natural by subtracting one.
>>>minusone (pos 1)Natural 0
>>>minusone (pos 5)Natural 4
A non-zero integer. True for positive, False for negative.
The Positive gives the absolute value.
>>>NotZero True (pos 3)NotZero True (Positive 3)
>>>NotZero False (pos 7)NotZero False (Positive 7)
Instances
| FromJSON NotZero Source # | Parses a
|
| ToJSON NotZero Source # | Serialises a
|
| Semigroup NotZero Source # | Semigroup under addition. Note: this is partial if the result would be zero.
Use
|
| Show NotZero Source # | |
| Eq NotZero Source # | |
| Ord NotZero Source # |
|
| AsNotZero NotZero Source # |
|
| AsPositive NotZero Source # | Prism from
|
| HasNotZero NotZero Source # |
|
class HasNotZero a where Source #
Instances
| HasNotZero MaxNotZero Source # |
|
| HasNotZero MinNotZero Source # |
|
| HasNotZero NotZero Source # |
|
| HasNotZero SumNotZero Source # |
|
class AsNotZero a where Source #
>>>(7 :: Integer) ^? _NotZeroJust (NotZero True (Positive 7))
>>>(-3 :: Integer) ^? _NotZeroJust (NotZero False (Positive 3))
>>>(0 :: Integer) ^? _NotZeroNothing
Instances
| AsNotZero MaxNotZero Source # |
|
| AsNotZero MinNotZero Source # |
|
| AsNotZero NotZero Source # |
|
| AsNotZero SumNotZero Source # |
|
| AsNotZero Integer Source # |
|
| AsNotZero Int Source # |
|
| AsNotZero Word Source # |
|
| Integral a => AsNotZero (Identity a) Source # |
|
| Integral a => AsNotZero (Const a b) Source # |
|
newtype SumNotZero Source #
>>>SumNotZero (NotZero True (pos 3)) <> SumNotZero (NotZero True (pos 4))SumNotZero (NotZero True (Positive 7))
Constructors
| SumNotZero NotZero |
Instances
| FromJSON SumNotZero Source # | Parses a
|
Defined in Natural | |
| ToJSON SumNotZero Source # | Serialises a
|
Defined in Natural Methods toJSON :: SumNotZero -> Value # toEncoding :: SumNotZero -> Encoding # toJSONList :: [SumNotZero] -> Value # toEncodingList :: [SumNotZero] -> Encoding # omitField :: SumNotZero -> Bool # | |
| Semigroup SumNotZero Source # |
|
Defined in Natural Methods (<>) :: SumNotZero -> SumNotZero -> SumNotZero # sconcat :: NonEmpty SumNotZero -> SumNotZero # stimes :: Integral b => b -> SumNotZero -> SumNotZero # | |
| Show SumNotZero Source # | |
Defined in Natural Methods showsPrec :: Int -> SumNotZero -> ShowS # show :: SumNotZero -> String # showList :: [SumNotZero] -> ShowS # | |
| Eq SumNotZero Source # | |
Defined in Natural | |
| Ord SumNotZero Source # | |
Defined in Natural Methods compare :: SumNotZero -> SumNotZero -> Ordering # (<) :: SumNotZero -> SumNotZero -> Bool # (<=) :: SumNotZero -> SumNotZero -> Bool # (>) :: SumNotZero -> SumNotZero -> Bool # (>=) :: SumNotZero -> SumNotZero -> Bool # max :: SumNotZero -> SumNotZero -> SumNotZero # min :: SumNotZero -> SumNotZero -> SumNotZero # | |
| Wrapped SumNotZero Source # |
|
| AsNotZero SumNotZero Source # |
|
| HasNotZero SumNotZero Source # |
|
| SumNotZero ~ a => Rewrapped SumNotZero a Source # | |
Defined in Natural | |
| type Unwrapped SumNotZero Source # | |
Defined in Natural | |
newtype MaxNotZero Source #
>>>MaxNotZero (NotZero True (pos 3)) <> MaxNotZero (NotZero True (pos 7))MaxNotZero (NotZero True (Positive 7))
>>>MaxNotZero (NotZero False (pos 3)) <> MaxNotZero (NotZero True (pos 1))MaxNotZero (NotZero True (Positive 1))
Constructors
| MaxNotZero NotZero |
Instances
| FromJSON MaxNotZero Source # | Parses a
|
Defined in Natural | |
| ToJSON MaxNotZero Source # | Serialises a
|
Defined in Natural Methods toJSON :: MaxNotZero -> Value # toEncoding :: MaxNotZero -> Encoding # toJSONList :: [MaxNotZero] -> Value # toEncodingList :: [MaxNotZero] -> Encoding # omitField :: MaxNotZero -> Bool # | |
| Semigroup MaxNotZero Source # |
|
Defined in Natural Methods (<>) :: MaxNotZero -> MaxNotZero -> MaxNotZero # sconcat :: NonEmpty MaxNotZero -> MaxNotZero # stimes :: Integral b => b -> MaxNotZero -> MaxNotZero # | |
| Show MaxNotZero Source # | |
Defined in Natural Methods showsPrec :: Int -> MaxNotZero -> ShowS # show :: MaxNotZero -> String # showList :: [MaxNotZero] -> ShowS # | |
| Eq MaxNotZero Source # | |
Defined in Natural | |
| Ord MaxNotZero Source # | |
Defined in Natural Methods compare :: MaxNotZero -> MaxNotZero -> Ordering # (<) :: MaxNotZero -> MaxNotZero -> Bool # (<=) :: MaxNotZero -> MaxNotZero -> Bool # (>) :: MaxNotZero -> MaxNotZero -> Bool # (>=) :: MaxNotZero -> MaxNotZero -> Bool # max :: MaxNotZero -> MaxNotZero -> MaxNotZero # min :: MaxNotZero -> MaxNotZero -> MaxNotZero # | |
| Wrapped MaxNotZero Source # |
|
| AsNotZero MaxNotZero Source # |
|
| HasNotZero MaxNotZero Source # |
|
| MaxNotZero ~ a => Rewrapped MaxNotZero a Source # | |
Defined in Natural | |
| type Unwrapped MaxNotZero Source # | |
Defined in Natural | |
newtype MinNotZero Source #
>>>MinNotZero (NotZero True (pos 3)) <> MinNotZero (NotZero True (pos 7))MinNotZero (NotZero True (Positive 3))
>>>MinNotZero (NotZero False (pos 3)) <> MinNotZero (NotZero True (pos 1))MinNotZero (NotZero False (Positive 3))
Constructors
| MinNotZero NotZero |
Instances
| FromJSON MinNotZero Source # | Parses a
|
Defined in Natural | |
| ToJSON MinNotZero Source # | Serialises a
|
Defined in Natural Methods toJSON :: MinNotZero -> Value # toEncoding :: MinNotZero -> Encoding # toJSONList :: [MinNotZero] -> Value # toEncodingList :: [MinNotZero] -> Encoding # omitField :: MinNotZero -> Bool # | |
| Semigroup MinNotZero Source # |
|
Defined in Natural Methods (<>) :: MinNotZero -> MinNotZero -> MinNotZero # sconcat :: NonEmpty MinNotZero -> MinNotZero # stimes :: Integral b => b -> MinNotZero -> MinNotZero # | |
| Show MinNotZero Source # | |
Defined in Natural Methods showsPrec :: Int -> MinNotZero -> ShowS # show :: MinNotZero -> String # showList :: [MinNotZero] -> ShowS # | |
| Eq MinNotZero Source # | |
Defined in Natural | |
| Ord MinNotZero Source # | |
Defined in Natural Methods compare :: MinNotZero -> MinNotZero -> Ordering # (<) :: MinNotZero -> MinNotZero -> Bool # (<=) :: MinNotZero -> MinNotZero -> Bool # (>) :: MinNotZero -> MinNotZero -> Bool # (>=) :: MinNotZero -> MinNotZero -> Bool # max :: MinNotZero -> MinNotZero -> MinNotZero # min :: MinNotZero -> MinNotZero -> MinNotZero # | |
| Wrapped MinNotZero Source # |
|
| AsNotZero MinNotZero Source # |
|
| HasNotZero MinNotZero Source # |
|
| MinNotZero ~ a => Rewrapped MinNotZero a Source # | |
Defined in Natural | |
| type Unwrapped MinNotZero Source # | |
Defined in Natural | |
positiveNotZero :: Positive -> NotZero Source #
negativeNotZero :: Positive -> NotZero Source #
notZeroPositive :: NotZero -> Positive Source #
Extract the magnitude from a NotZero.
>>>notZeroPositive (NotZero True (pos 5))Positive 5
>>>notZeroPositive (NotZero False (pos 3))Positive 3
notZeroInteger :: NotZero -> Integer Source #
isPositive :: NotZero -> Bool Source #
Test if a NotZero is positive.
>>>isPositive (NotZero True (pos 5))True
>>>isPositive (NotZero False (pos 5))False
isNegative :: NotZero -> Bool Source #
Test if a NotZero is negative.
>>>isNegative (NotZero False (pos 5))True
>>>isNegative (NotZero True (pos 5))False
negateNZ :: NotZero -> NotZero Source #
Negate a NotZero.
>>>negateNZ (NotZero True (pos 5))NotZero False (Positive 5)
>>>negateNZ (NotZero False (pos 3))NotZero True (Positive 3)
absoluteNZ :: NotZero -> Positive Source #
Absolute value as a Positive.
>>>absoluteNZ (NotZero True (pos 5))Positive 5
>>>absoluteNZ (NotZero False (pos 3))Positive 3
signumNZ :: NotZero -> NotZero Source #
Signum: positive one or negative one.
>>>signumNZ (NotZero True (pos 99))NotZero True (Positive 1)
>>>signumNZ (NotZero False (pos 42))NotZero False (Positive 1)
plusNZ :: NotZero -> NotZero -> Maybe NotZero Source #
Add two NotZero values. Returns Nothing if the result is zero.
>>>plusNZ (NotZero True (pos 3)) (NotZero True (pos 4))Just (NotZero True (Positive 7))
>>>plusNZ (NotZero True (pos 3)) (NotZero False (pos 3))Nothing
>>>plusNZ (NotZero True (pos 5)) (NotZero False (pos 3))Just (NotZero True (Positive 2))
>>>plusNZ (NotZero False (pos 5)) (NotZero True (pos 3))Just (NotZero False (Positive 2))
multiplyNZ :: NotZero -> NotZero -> NotZero Source #
Multiply two NotZero values. Always non-zero.
>>>multiplyNZ (NotZero True (pos 3)) (NotZero True (pos 4))NotZero True (Positive 12)
>>>multiplyNZ (NotZero False (pos 3)) (NotZero True (pos 4))NotZero False (Positive 12)
>>>multiplyNZ (NotZero False (pos 3)) (NotZero False (pos 4))NotZero True (Positive 12)
notZeroOr :: AsNotZero a => a -> NotZero Source #
Return the NotZero if the prism matches, otherwise positive one.
>>>notZeroOr (5 :: Integer)NotZero True (Positive 5)
>>>notZeroOr (0 :: Integer)NotZero True (Positive 1)
>>>notZeroOr (-3 :: Integer)NotZero False (Positive 3)
toJsonNatural :: HasNatural a => a -> Value Source #
Serialises any value with a HasNatural instance to a JSON Value.
>>>toJsonNatural (nat 42)Number 42.0
>>>toJsonNatural (ProductNatural (nat 12))Number 12.0
>>>toJsonNatural (MaxNatural (nat 7))Number 7.0
>>>toJsonNatural (MinNatural (nat 3))Number 3.0
parseJsonNatural :: Value -> Parser Natural Source #
Parses a JSON value into a Natural, failing on negative values.
>>>parse parseJsonNatural (Number 42)Success (Natural 42)
>>>parse parseJsonNatural (Number 0)Success (Natural 0)
>>>parse parseJsonNatural (Number (-1))Error "parse failed, Natural: expected non-negative integer"
toJsonPositive :: HasPositive a => a -> Value Source #
Serialises any value with a HasPositive instance to a JSON Value.
>>>toJsonPositive (pos 42)Number 42.0
>>>toJsonPositive (SumPositive (pos 7))Number 7.0
>>>toJsonPositive (MaxPositive (pos 7))Number 7.0
>>>toJsonPositive (MinPositive (pos 3))Number 3.0
parseJsonPositive :: Value -> Parser Positive Source #
Parses a JSON value into a Positive, failing on non-positive values.
>>>parse parseJsonPositive (Number 42)Success (Positive 42)
>>>parse parseJsonPositive (Number 1)Success (Positive 1)
>>>parse parseJsonPositive (Number 0)Error "parse failed, Positive: expected positive integer"
>>>parse parseJsonPositive (Number (-1))Error "parse failed, Positive: expected positive integer"
toJsonNotZero :: HasNotZero a => a -> Value Source #
Serialises any value with a HasNotZero instance to a JSON Value.
>>>toJsonNotZero (NotZero True (pos 5))Number 5.0
>>>toJsonNotZero (NotZero False (pos 3))Number (-3.0)
>>>toJsonNotZero (SumNotZero (NotZero True (pos 7)))Number 7.0
>>>toJsonNotZero (MaxNotZero (NotZero False (pos 2)))Number (-2.0)
>>>toJsonNotZero (MinNotZero (NotZero True (pos 1)))Number 1.0
parseJsonNotZero :: Value -> Parser NotZero Source #
Parses a JSON value into a NotZero, failing on zero.
>>>parse parseJsonNotZero (Number 5)Success (NotZero True (Positive 5))
>>>parse parseJsonNotZero (Number (-3))Success (NotZero False (Positive 3))
>>>parse parseJsonNotZero (Number 0)Error "parse failed, NotZero: expected non-zero integer"