ouroboros-consensus-0.1.0.0: Consensus layer for the Ouroboros blockchain protocol
Safe HaskellNone
LanguageHaskell2010

Ouroboros.Consensus.Util.Counting

Description

Type-level counting

Intended for unqualified import.

Synopsis

Documentation

newtype Exactly xs a Source #

Constructors

Exactly 

Fields

Bundled Patterns

pattern ExactlyNil :: () => xs ~ '[] => Exactly xs a 
pattern ExactlyCons :: () => xs' ~ (x ': xs) => a -> Exactly xs a -> Exactly xs' a 

Instances

Instances details
Functor (Exactly xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

fmap :: (a -> b) -> Exactly xs a -> Exactly xs b #

(<$) :: a -> Exactly xs b -> Exactly xs a #

Foldable (Exactly xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

fold :: Monoid m => Exactly xs m -> m #

foldMap :: Monoid m => (a -> m) -> Exactly xs a -> m #

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

foldr :: (a -> b -> b) -> b -> Exactly xs a -> b #

foldr' :: (a -> b -> b) -> b -> Exactly xs a -> b #

foldl :: (b -> a -> b) -> b -> Exactly xs a -> b #

foldl' :: (b -> a -> b) -> b -> Exactly xs a -> b #

foldr1 :: (a -> a -> a) -> Exactly xs a -> a #

foldl1 :: (a -> a -> a) -> Exactly xs a -> a #

toList :: Exactly xs a -> [a] #

null :: Exactly xs a -> Bool #

length :: Exactly xs a -> Int #

elem :: Eq a => a -> Exactly xs a -> Bool #

maximum :: Ord a => Exactly xs a -> a #

minimum :: Ord a => Exactly xs a -> a #

sum :: Num a => Exactly xs a -> a #

product :: Num a => Exactly xs a -> a #

Traversable (Exactly xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

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

sequenceA :: Applicative f => Exactly xs (f a) -> f (Exactly xs a) #

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

sequence :: Monad m => Exactly xs (m a) -> m (Exactly xs a) #

Eq a => Eq (Exactly xs a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

(==) :: Exactly xs a -> Exactly xs a -> Bool #

(/=) :: Exactly xs a -> Exactly xs a -> Bool #

Show a => Show (Exactly xs a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

showsPrec :: Int -> Exactly xs a -> ShowS #

show :: Exactly xs a -> String #

showList :: [Exactly xs a] -> ShowS #

data AtMost :: [Type] -> Type -> Type where Source #

At most one value for each type level index

Constructors

AtMostNil :: AtMost xs a 
AtMostCons :: !a -> !(AtMost xs a) -> AtMost (x ': xs) a 

Instances

Instances details
Functor (AtMost xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

fmap :: (a -> b) -> AtMost xs a -> AtMost xs b #

(<$) :: a -> AtMost xs b -> AtMost xs a #

Foldable (AtMost xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

fold :: Monoid m => AtMost xs m -> m #

foldMap :: Monoid m => (a -> m) -> AtMost xs a -> m #

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

foldr :: (a -> b -> b) -> b -> AtMost xs a -> b #

foldr' :: (a -> b -> b) -> b -> AtMost xs a -> b #

foldl :: (b -> a -> b) -> b -> AtMost xs a -> b #

foldl' :: (b -> a -> b) -> b -> AtMost xs a -> b #

foldr1 :: (a -> a -> a) -> AtMost xs a -> a #

foldl1 :: (a -> a -> a) -> AtMost xs a -> a #

toList :: AtMost xs a -> [a] #

null :: AtMost xs a -> Bool #

length :: AtMost xs a -> Int #

elem :: Eq a => a -> AtMost xs a -> Bool #

maximum :: Ord a => AtMost xs a -> a #

minimum :: Ord a => AtMost xs a -> a #

sum :: Num a => AtMost xs a -> a #

product :: Num a => AtMost xs a -> a #

Traversable (AtMost xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

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

sequenceA :: Applicative f => AtMost xs (f a) -> f (AtMost xs a) #

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

sequence :: Monad m => AtMost xs (m a) -> m (AtMost xs a) #

Eq a => Eq (AtMost xs a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

(==) :: AtMost xs a -> AtMost xs a -> Bool #

(/=) :: AtMost xs a -> AtMost xs a -> Bool #

Show a => Show (AtMost xs a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

showsPrec :: Int -> AtMost xs a -> ShowS #

show :: AtMost xs a -> String #

showList :: [AtMost xs a] -> ShowS #

data NonEmpty :: [Type] -> Type -> Type where Source #

Non-empty variation on AtMost

Constructors

NonEmptyOne :: !a -> NonEmpty (x ': xs) a 
NonEmptyCons :: !a -> !(NonEmpty xs a) -> NonEmpty (x ': xs) a 

Instances

Instances details
Functor (NonEmpty xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

fmap :: (a -> b) -> NonEmpty xs a -> NonEmpty xs b #

(<$) :: a -> NonEmpty xs b -> NonEmpty xs a #

IsNonEmpty xs => Applicative (NonEmpty xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

pure :: a -> NonEmpty xs a #

(<*>) :: NonEmpty xs (a -> b) -> NonEmpty xs a -> NonEmpty xs b #

liftA2 :: (a -> b -> c) -> NonEmpty xs a -> NonEmpty xs b -> NonEmpty xs c #

(*>) :: NonEmpty xs a -> NonEmpty xs b -> NonEmpty xs b #

(<*) :: NonEmpty xs a -> NonEmpty xs b -> NonEmpty xs a #

Foldable (NonEmpty xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

fold :: Monoid m => NonEmpty xs m -> m #

foldMap :: Monoid m => (a -> m) -> NonEmpty xs a -> m #

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

foldr :: (a -> b -> b) -> b -> NonEmpty xs a -> b #

foldr' :: (a -> b -> b) -> b -> NonEmpty xs a -> b #

foldl :: (b -> a -> b) -> b -> NonEmpty xs a -> b #

foldl' :: (b -> a -> b) -> b -> NonEmpty xs a -> b #

foldr1 :: (a -> a -> a) -> NonEmpty xs a -> a #

foldl1 :: (a -> a -> a) -> NonEmpty xs a -> a #

toList :: NonEmpty xs a -> [a] #

null :: NonEmpty xs a -> Bool #

length :: NonEmpty xs a -> Int #

elem :: Eq a => a -> NonEmpty xs a -> Bool #

maximum :: Ord a => NonEmpty xs a -> a #

minimum :: Ord a => NonEmpty xs a -> a #

sum :: Num a => NonEmpty xs a -> a #

product :: Num a => NonEmpty xs a -> a #

Traversable (NonEmpty xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

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

sequenceA :: Applicative f => NonEmpty xs (f a) -> f (NonEmpty xs a) #

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

sequence :: Monad m => NonEmpty xs (m a) -> m (NonEmpty xs a) #

Eq a => Eq (NonEmpty xs a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

(==) :: NonEmpty xs a -> NonEmpty xs a -> Bool #

(/=) :: NonEmpty xs a -> NonEmpty xs a -> Bool #

Show a => Show (NonEmpty xs a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

showsPrec :: Int -> NonEmpty xs a -> ShowS #

show :: NonEmpty xs a -> String #

showList :: [NonEmpty xs a] -> ShowS #

Working with Exactly

exactlyOne :: a -> Exactly '[x] a Source #

Singleton

exactlyTwo :: a -> a -> Exactly '[x, y] a Source #

From a pair

exactlyHead :: Exactly (x ': xs) a -> a Source #

Analogue of head

exactlyTail :: Exactly (x ': xs) a -> Exactly xs a Source #

Analogue of tail

exactlyZip :: Exactly xs a -> Exactly xs b -> Exactly xs (a, b) Source #

Analogue of zip

exactlyZipFoldable :: Foldable t => Exactly xs a -> t b -> AtMost xs (a, b) Source #

Analogue of zip where the length of second argument is unknown

exactlyWeakenNonEmpty :: Exactly (x ': xs) a -> NonEmpty (x ': xs) a Source #

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.

Working with AtMost

atMostOne :: a -> AtMost (x ': xs) a Source #

Singleton

atMostInit :: AtMost xs a -> Maybe (AtMost xs a, a) Source #

Analogue of init

For simplicity we don't shrink the type-level index.

atMostHead :: AtMost xs a -> Maybe a Source #

Analogue of head

atMostLast :: AtMost xs a -> Maybe a Source #

Analogue of last

atMostZipFoldable :: Foldable t => AtMost xs a -> t b -> AtMost xs (a, b) Source #

atMostNonEmpty :: AtMost (x ': xs) a -> Maybe (NonEmpty (x ': xs) a) Source #

Working with NonEmpty

nonEmptyHead :: NonEmpty xs a -> a Source #

Analogue of head

nonEmptyLast :: NonEmpty xs a -> a Source #

Analogue of last

nonEmptyInit :: NonEmpty xs a -> (Maybe (NonEmpty xs a), a) Source #

Analogue of init

nonEmptyFromList :: forall xs a. SListI xs => [a] -> Maybe (NonEmpty xs a) Source #

Build a NonEmpty from a list. Returns Nothing when the list is empty or when it's longer than xs.

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
   ]

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