Safe Haskell  None 

Language  Haskell2010 
Typelevel counting
Intended for unqualified import.
Synopsis

data
AtMost
:: [
Type
] >
Type
>
Type
where
 AtMostNil :: AtMost xs a
 AtMostCons :: !a > !( AtMost xs a) > AtMost (x ': xs) a

newtype
Exactly
xs a
where

Exactly
{
 getExactly :: NP ( K a) xs
 pattern ExactlyNil :: () => xs ~ '[] => Exactly xs a
 pattern ExactlyCons :: () => xs' ~ (x ': xs) => a > Exactly xs a > Exactly xs' a

Exactly
{

data
NonEmpty
:: [
Type
] >
Type
>
Type
where
 NonEmptyOne :: !a > NonEmpty (x ': xs) a
 NonEmptyCons :: !a > !( NonEmpty xs a) > NonEmpty (x ': xs) a
 exactlyHead :: Exactly (x ': xs) a > a
 exactlyOne :: a > Exactly '[x] a
 exactlyReplicate :: forall a r. Word > a > ( forall xs. Exactly xs a > r) > r
 exactlyTail :: Exactly (x ': xs) a > Exactly xs a
 exactlyTwo :: a > a > Exactly '[x, y] a
 exactlyWeaken :: Exactly xs a > AtMost xs a
 exactlyWeakenNonEmpty :: Exactly (x ': xs) a > NonEmpty (x ': xs) a
 exactlyZip :: Exactly xs a > Exactly xs b > Exactly xs (a, b)
 exactlyZipFoldable :: Foldable t => Exactly xs a > t b > AtMost xs (a, b)
 atMostHead :: AtMost xs a > Maybe a
 atMostInit :: AtMost xs a > Maybe ( AtMost xs a, a)
 atMostLast :: AtMost xs a > Maybe a
 atMostNonEmpty :: AtMost (x ': xs) a > Maybe ( NonEmpty (x ': xs) a)
 atMostOne :: a > AtMost (x ': xs) a
 atMostZipFoldable :: Foldable t => AtMost xs a > t b > AtMost xs (a, b)
 nonEmptyFromList :: forall xs a. SListI xs => [a] > Maybe ( NonEmpty xs a)
 nonEmptyHead :: NonEmpty xs a > a
 nonEmptyInit :: NonEmpty xs a > ( Maybe ( NonEmpty xs a), a)
 nonEmptyLast :: NonEmpty xs a > a
 nonEmptyMapOne :: forall m xs a. Alternative m => (a > m a) > NonEmpty xs a > m ( NonEmpty xs a)
 nonEmptyMapTwo :: forall m xs a. Alternative m => (a > m a) > (a > a > m (a, a)) > NonEmpty xs a > m ( NonEmpty xs a)
 nonEmptyStrictPrefixes :: NonEmpty xs a > [ NonEmpty xs a]
 nonEmptyToList :: forall xs a. NonEmpty xs a > [a]
 nonEmptyWeaken :: NonEmpty xs a > AtMost xs a
Documentation
data AtMost :: [ Type ] > Type > Type where Source #
At most one value for each type level index
AtMostNil :: AtMost xs a  
AtMostCons :: !a > !( AtMost xs a) > AtMost (x ': xs) a 
Instances
Functor ( AtMost xs) Source #  
Foldable ( AtMost xs) Source #  
Defined in Ouroboros.Consensus.Util.Counting fold :: Monoid m => AtMost xs m > m Source # foldMap :: Monoid m => (a > m) > AtMost xs a > m Source # foldMap' :: Monoid m => (a > m) > AtMost xs a > m Source # foldr :: (a > b > b) > b > AtMost xs a > b Source # foldr' :: (a > b > b) > b > AtMost xs a > b Source # foldl :: (b > a > b) > b > AtMost xs a > b Source # foldl' :: (b > a > b) > b > AtMost xs a > b Source # foldr1 :: (a > a > a) > AtMost xs a > a Source # foldl1 :: (a > a > a) > AtMost xs a > a Source # toList :: AtMost xs a > [a] Source # null :: AtMost xs a > Bool Source # length :: AtMost xs a > Int Source # elem :: Eq a => a > AtMost xs a > Bool Source # maximum :: Ord a => AtMost xs a > a Source # minimum :: Ord a => AtMost xs a > a Source # 

Traversable ( AtMost xs) Source #  
Defined in Ouroboros.Consensus.Util.Counting traverse :: Applicative f => (a > f b) > AtMost xs a > f ( AtMost xs b) Source # sequenceA :: Applicative f => AtMost xs (f a) > f ( AtMost xs a) Source # mapM :: Monad m => (a > m b) > AtMost xs a > m ( AtMost xs b) Source # sequence :: Monad m => AtMost xs (m a) > m ( AtMost xs a) Source # 

Eq a => Eq ( AtMost xs a) Source #  
Show a => Show ( AtMost xs a) Source #  
Exactly  

pattern ExactlyNil :: () => xs ~ '[] => Exactly xs a  
pattern ExactlyCons :: () => xs' ~ (x ': xs) => a > Exactly xs a > Exactly xs' a 
Instances
Functor ( Exactly xs) Source #  
Foldable ( Exactly xs) Source #  
Defined in Ouroboros.Consensus.Util.Counting fold :: Monoid m => Exactly xs m > m Source # foldMap :: Monoid m => (a > m) > Exactly xs a > m Source # foldMap' :: Monoid m => (a > m) > Exactly xs a > m Source # foldr :: (a > b > b) > b > Exactly xs a > b Source # foldr' :: (a > b > b) > b > Exactly xs a > b Source # foldl :: (b > a > b) > b > Exactly xs a > b Source # foldl' :: (b > a > b) > b > Exactly xs a > b Source # foldr1 :: (a > a > a) > Exactly xs a > a Source # foldl1 :: (a > a > a) > Exactly xs a > a Source # toList :: Exactly xs a > [a] Source # null :: Exactly xs a > Bool Source # length :: Exactly xs a > Int Source # elem :: Eq a => a > Exactly xs a > Bool Source # maximum :: Ord a => Exactly xs a > a Source # minimum :: Ord a => Exactly xs a > a Source # 

Traversable ( Exactly xs) Source #  
Defined in Ouroboros.Consensus.Util.Counting traverse :: Applicative f => (a > f b) > Exactly xs a > f ( Exactly xs b) Source # sequenceA :: Applicative f => Exactly xs (f a) > f ( Exactly xs a) Source # mapM :: Monad m => (a > m b) > Exactly xs a > m ( Exactly xs b) Source # sequence :: Monad m => Exactly xs (m a) > m ( Exactly xs a) Source # 

Eq a => Eq ( Exactly xs a) Source #  
Show a => Show ( Exactly xs a) Source #  
data NonEmpty :: [ Type ] > Type > Type where Source #
Nonempty variation on
AtMost
NonEmptyOne :: !a > NonEmpty (x ': xs) a  
NonEmptyCons :: !a > !( NonEmpty xs a) > NonEmpty (x ': xs) a 
Instances
Working with
Exactly
exactlyHead :: Exactly (x ': xs) a > a Source #
Analogue of
head
exactlyOne :: a > Exactly '[x] a Source #
Singleton
exactlyReplicate :: forall a r. Word > a > ( forall xs. Exactly xs a > r) > r Source #
Analogue of
replicate
In CPS style because the
xs
type parameter is not statically known.
exactlyTwo :: a > a > Exactly '[x, y] a Source #
From a pair
exactlyWeaken :: Exactly xs a > AtMost xs a Source #
exactlyWeakenNonEmpty :: Exactly (x ': xs) a > NonEmpty (x ': xs) a Source #
exactlyZipFoldable :: Foldable t => Exactly xs a > t b > AtMost xs (a, b) Source #
Analogue of
zip
where the length of second argument is unknown
Working with
AtMost
atMostInit :: AtMost xs a > Maybe ( AtMost xs a, a) Source #
Analogue of
init
For simplicity we don't shrink the typelevel index.
Working with
NonEmpty
nonEmptyHead :: NonEmpty xs a > a Source #
Analogue of
head
nonEmptyLast :: NonEmpty xs a > a Source #
Analogue of
last
nonEmptyMapOne :: forall m xs a. Alternative m => (a > m a) > NonEmpty xs a > m ( NonEmpty xs a) Source #
Apply the specified function to exactly one element
nonEmptyMapTwo :: forall m xs a. Alternative m => (a > m a) > (a > a > m (a, a)) > NonEmpty xs a > m ( NonEmpty xs a) Source #
Variation on
nonEmptyMapOne
where we try to apply the function to
pairs
of elements
nonEmptyStrictPrefixes :: NonEmpty xs a > [ NonEmpty xs a] Source #
A strict prefixes
nonEmptyStrictPrefixes (fromJust (nonEmptyFromList [1..4])) == [ NonEmptyOne 1 , NonEmptyCons 1 $ NonEmptyOne 2 , NonEmptyCons 1 $ NonEmptyCons 2 $ NonEmptyOne 3 ]
nonEmptyToList :: forall xs a. NonEmpty xs a > [a] Source #
Convert a
NonEmpty
to a list.
nonEmptyWeaken :: NonEmpty xs a > AtMost xs a Source #