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

Ouroboros.Consensus.Util.Counting

Description

Type-level counting

Intended for unqualified import.

Synopsis

Documentation

data AtMost ∷ [Type] → TypeType where Source #

At most one value for each type level index

Constructors

AtMostNilAtMost 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

Methods

foldMonoid m ⇒ AtMost xs m → m Source #

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

toListAtMost xs a → [a] Source #

nullAtMost xs a → Bool Source #

lengthAtMost xs a → Int Source #

elemEq a ⇒ a → AtMost xs a → Bool Source #

maximumOrd a ⇒ AtMost xs a → a Source #

minimumOrd a ⇒ AtMost xs a → a Source #

sumNum a ⇒ AtMost xs a → a Source #

productNum a ⇒ AtMost xs a → a Source #

Traversable (AtMost xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

traverseApplicative f ⇒ (a → f b) → AtMost xs a → f (AtMost xs b) Source #

sequenceAApplicative f ⇒ AtMost xs (f a) → f (AtMost xs a) Source #

mapMMonad m ⇒ (a → m b) → AtMost xs a → m (AtMost xs b) Source #

sequenceMonad 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

Methods

(==)AtMost xs a → AtMost xs a → Bool Source #

(/=)AtMost xs a → AtMost xs a → Bool Source #

Show a ⇒ Show (AtMost xs a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

showsPrecIntAtMost xs a → ShowS Source #

showAtMost xs a → String Source #

showList ∷ [AtMost xs a] → ShowS Source #

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

Methods

foldMonoid m ⇒ Exactly xs m → m Source #

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

toListExactly xs a → [a] Source #

nullExactly xs a → Bool Source #

lengthExactly xs a → Int Source #

elemEq a ⇒ a → Exactly xs a → Bool Source #

maximumOrd a ⇒ Exactly xs a → a Source #

minimumOrd a ⇒ Exactly xs a → a Source #

sumNum a ⇒ Exactly xs a → a Source #

productNum a ⇒ Exactly xs a → a Source #

Traversable (Exactly xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

traverseApplicative f ⇒ (a → f b) → Exactly xs a → f (Exactly xs b) Source #

sequenceAApplicative f ⇒ Exactly xs (f a) → f (Exactly xs a) Source #

mapMMonad m ⇒ (a → m b) → Exactly xs a → m (Exactly xs b) Source #

sequenceMonad m ⇒ Exactly xs (m a) → m (Exactly xs a) Source #

Eq a ⇒ Eq (Exactly xs a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

(==)Exactly xs a → Exactly xs a → Bool Source #

(/=)Exactly xs a → Exactly xs a → Bool Source #

Show a ⇒ Show (Exactly xs a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

showsPrecIntExactly xs a → ShowS Source #

showExactly xs a → String Source #

showList ∷ [Exactly xs a] → ShowS Source #

data NonEmpty ∷ [Type] → TypeType 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 Source #

(<$) ∷ a → NonEmpty xs b → NonEmpty xs a Source #

IsNonEmpty xs ⇒ Applicative (NonEmpty xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

pure ∷ a → NonEmpty xs a Source #

(<*>)NonEmpty xs (a → b) → NonEmpty xs a → NonEmpty xs b Source #

liftA2 ∷ (a → b → c) → NonEmpty xs a → NonEmpty xs b → NonEmpty xs c Source #

(*>)NonEmpty xs a → NonEmpty xs b → NonEmpty xs b Source #

(<*)NonEmpty xs a → NonEmpty xs b → NonEmpty xs a Source #

Foldable (NonEmpty xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

foldMonoid m ⇒ NonEmpty xs m → m Source #

foldMapMonoid m ⇒ (a → m) → NonEmpty xs a → m Source #

foldMap'Monoid m ⇒ (a → m) → NonEmpty xs a → m Source #

foldr ∷ (a → b → b) → b → NonEmpty xs a → b Source #

foldr' ∷ (a → b → b) → b → NonEmpty xs a → b Source #

foldl ∷ (b → a → b) → b → NonEmpty xs a → b Source #

foldl' ∷ (b → a → b) → b → NonEmpty xs a → b Source #

foldr1 ∷ (a → a → a) → NonEmpty xs a → a Source #

foldl1 ∷ (a → a → a) → NonEmpty xs a → a Source #

toListNonEmpty xs a → [a] Source #

nullNonEmpty xs a → Bool Source #

lengthNonEmpty xs a → Int Source #

elemEq a ⇒ a → NonEmpty xs a → Bool Source #

maximumOrd a ⇒ NonEmpty xs a → a Source #

minimumOrd a ⇒ NonEmpty xs a → a Source #

sumNum a ⇒ NonEmpty xs a → a Source #

productNum a ⇒ NonEmpty xs a → a Source #

Traversable (NonEmpty xs) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

traverseApplicative f ⇒ (a → f b) → NonEmpty xs a → f (NonEmpty xs b) Source #

sequenceAApplicative f ⇒ NonEmpty xs (f a) → f (NonEmpty xs a) Source #

mapMMonad m ⇒ (a → m b) → NonEmpty xs a → m (NonEmpty xs b) Source #

sequenceMonad m ⇒ NonEmpty xs (m a) → m (NonEmpty xs a) Source #

Eq a ⇒ Eq (NonEmpty xs a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

(==)NonEmpty xs a → NonEmpty xs a → Bool Source #

(/=)NonEmpty xs a → NonEmpty xs a → Bool Source #

Show a ⇒ Show (NonEmpty xs a) Source # 
Instance details

Defined in Ouroboros.Consensus.Util.Counting

Methods

showsPrecIntNonEmpty xs a → ShowS Source #

showNonEmpty xs a → String Source #

showList ∷ [NonEmpty xs a] → ShowS Source #

Working with Exactly

exactlyHeadExactly (x ': xs) a → a Source #

Analogue of head

exactlyOne ∷ a → Exactly '[x] a Source #

Singleton

exactlyReplicate ∷ ∀ a r. Word → a → (∀ xs. Exactly xs a → r) → r Source #

Analogue of replicate

In CPS style because the xs type parameter is not statically known.

exactlyTailExactly (x ': xs) a → Exactly xs a Source #

Analogue of tail

exactlyTwo ∷ a → a → Exactly '[x, y] a Source #

From a pair

exactlyWeakenExactly xs a → AtMost xs a Source #

exactlyWeakenNonEmptyExactly (x ': xs) a → NonEmpty (x ': xs) a Source #

exactlyZipExactly xs a → Exactly xs b → Exactly xs (a, b) Source #

Analogue of zip

exactlyZipFoldableFoldable 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

atMostHeadAtMost xs a → Maybe a Source #

Analogue of head

atMostInitAtMost xs a → Maybe (AtMost xs a, a) Source #

Analogue of init

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

atMostLastAtMost xs a → Maybe a Source #

Analogue of last

atMostNonEmptyAtMost (x ': xs) a → Maybe (NonEmpty (x ': xs) a) Source #

atMostOne ∷ a → AtMost (x ': xs) a Source #

Singleton

atMostZipFoldableFoldable t ⇒ AtMost xs a → t b → AtMost xs (a, b) Source #

Working with NonEmpty

nonEmptyFromList ∷ ∀ 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.

nonEmptyHeadNonEmpty xs a → a Source #

Analogue of head

nonEmptyInitNonEmpty xs a → (Maybe (NonEmpty xs a), a) Source #

Analogue of init

nonEmptyLastNonEmpty xs a → a Source #

Analogue of last

nonEmptyMapOne ∷ ∀ 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 ∷ ∀ 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

nonEmptyStrictPrefixesNonEmpty 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 ∷ ∀ xs a. NonEmpty xs a → [a] Source #

Convert a NonEmpty to a list.