ouroboros-consensus-0.1.0.1: Consensus layer for the Ouroboros blockchain protocol
Safe Haskell None
Language Haskell2010

Ouroboros.Consensus.Util.Counting

Description

Type-level counting

Intended for unqualified import.

Synopsis

Documentation

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 Source #

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

Foldable ( AtMost xs) Source #
Instance details

Defined in Ouroboros.Consensus.Util.Counting

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) 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 #
Instance details

Defined in Ouroboros.Consensus.Util.Counting

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

Defined in Ouroboros.Consensus.Util.Counting

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 Source #

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

Foldable ( Exactly xs) Source #
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Traversable ( Exactly xs) Source #
Instance details

Defined in Ouroboros.Consensus.Util.Counting

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

Defined in Ouroboros.Consensus.Util.Counting

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

Defined in Ouroboros.Consensus.Util.Counting

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

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

Defined in Ouroboros.Consensus.Util.Counting

Foldable ( NonEmpty xs) Source #
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Traversable ( NonEmpty xs) Source #
Instance details

Defined in Ouroboros.Consensus.Util.Counting

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

Defined in Ouroboros.Consensus.Util.Counting

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

Defined in Ouroboros.Consensus.Util.Counting

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

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 type-level index.

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

Singleton

Working with NonEmpty

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 .

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.